From 8e626a60586e56e65395a478c0b5d4123b235c59 Mon Sep 17 00:00:00 2001 From: nihilazo Date: Fri, 1 Apr 2022 17:01:32 +0100 Subject: [PATCH] add function signature and tests for count-square --- main-test.rkt | 28 +++++++++++++++++++++++++++- main.rkt | 4 ++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/main-test.rkt b/main-test.rkt index dd62556..bdcf749 100644 --- a/main-test.rkt +++ b/main-test.rkt @@ -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) +) \ No newline at end of file diff --git a/main.rkt b/main.rkt index 4355c5d..80bbf58 100644 --- a/main.rkt +++ b/main.rkt @@ -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)