add function signature and tests for count-square

This commit is contained in:
Nico 2022-04-01 17:01:32 +01:00
parent 8fd5dd41b0
commit 8e626a6058
2 changed files with 31 additions and 1 deletions

View File

@ -31,7 +31,10 @@
(test-case
"valid-move?"
(define grid (list (line (point 0 0) (point 0 1) 1) (line (point 0 1) (point 0 2) 0) (line (point 3 2) (point 3 3) 0)))
(define grid (list
(line (point 0 0) (point 0 1) 1)
(line (point 0 1) (point 0 2) 0)
(line (point 3 2) (point 3 3) 0)))
(check-false (valid-move? (line (point 0 0) (point 0 1) 1) grid))
(check-true (valid-move? (line (point 0 2) (point 0 3) 0) grid)) ; not overwriting existing moves
(check-false (valid-move? (line (point 0 2) (point 0 1) 1) grid)) ; moving forward
@ -52,3 +55,26 @@
(check-true (forwards? (line (point 0 0) (point 0 1) 1)))
(check-true (forwards? (line (point 0 1) (point 1 1) 1)))
(check-false (forwards? (line (point 1 1) (point 0 0) 0))))
; TODO
(test-case
"count-square"
(define grid (list
(line (point 0 0) (point 0 1) 1)
(line (point 0 1) (point 1 1) 0)
(line (point 1 0) (point 1 1) 1)
(line (point 0 0) (point 1 0) 0)
(line (point 1 1) (point 2 1) 0)
(line (point 2 0) (point 2 1) 1)
(line (point 2 0) (point 3 0) 0)
(line (point 3 3) (point 3 4) 0)
(line (point 3 3) (point 4 3) 0)
(line (point 4 3) (point 4 4) 0)
(line (point 3 4) (point 4 4) 0)
))
(check-equal? (count-square (point 0 0) grid) 4)
(check-equal? (count-square (point 0 1) grid) 3)
(check-equal? (count-square (point 0 2) grid) 2)
(check-equal? (count-square (point 3 2) grid) 1)
(check-equal? (count-square (point 0 4) grid) 0)
)

View File

@ -40,6 +40,10 @@
(equal? (line-to l1) (line-from l2))
(equal? (line-from l1) (line-to l2)))))
; Point Grid -> Number
; given a point that is the top-left corner of a square on the grid, returns the amount of edges surrounding that square.
(define (count-square p g) 0)
; Line -> Bool
; returns #t if the line is forwards (with forwards being moving right and down, higher end coord than start)
(define (forwards? line)