2022-03-30 19:12:43 +00:00
|
|
|
#lang racket
|
|
|
|
|
|
|
|
(require rackunit "main.rkt")
|
|
|
|
|
2022-04-04 11:07:36 +00:00
|
|
|
(define test-grid (grid (list
|
2022-04-02 21:55:30 +00:00
|
|
|
(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)
|
2022-04-04 11:07:36 +00:00
|
|
|
(line (point 3 4) (point 4 4) 0)) 6 6))
|
2022-04-02 21:55:30 +00:00
|
|
|
|
2022-04-05 10:14:06 +00:00
|
|
|
(test-case
|
|
|
|
"total-moves"
|
|
|
|
(check-equal? (total-moves (grid '() 2 2)) 4)
|
|
|
|
(check-equal? (total-moves (grid '() 4 5)) 31)
|
|
|
|
(check-equal? (total-moves (grid '() 2 6)) 16))
|
|
|
|
|
2022-03-30 19:12:43 +00:00
|
|
|
(test-case
|
|
|
|
"same-position?"
|
|
|
|
(check-true (same-position? (line (point 0 0) (point 0 1) 1)
|
|
|
|
(line (point 0 0) (point 0 1) 0)))
|
|
|
|
(check-true (same-position? (line (point 0 0) (point 0 1) 1)
|
|
|
|
(line (point 0 1) (point 0 0) 0)))
|
|
|
|
(check-true (same-position? (line (point 0 2) (point 0 1) 0)
|
|
|
|
(line (point 0 2) (point 0 1) 0)))
|
|
|
|
(check-false (same-position? (line (point 0 0) (point 0 1) 1)
|
|
|
|
(line (point 2 4) (point 0 3) 0))))
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
"valid-length?"
|
|
|
|
(check-true (valid-length? (line (point 0 0) (point 0 1) 1)))
|
|
|
|
(check-true (valid-length? (line (point 0 1) (point 0 0) 1)))
|
|
|
|
(check-false (valid-length? (line (point 0 0) (point 1 1) 0)))
|
|
|
|
(check-false (valid-length? (line (point 0 0) (point 0 2) 1)))
|
|
|
|
(check-false (valid-length? (line (point 0 0) (point 0 2) 1))))
|
|
|
|
|
2022-04-03 17:50:25 +00:00
|
|
|
(test-case
|
|
|
|
"boxes-for"
|
2022-04-05 10:14:06 +00:00
|
|
|
(check-equal? (boxes-for (line (point 0 0) (point 0 1) 1) test-grid) (list (point 0 0)))
|
|
|
|
(check-equal? (boxes-for (line (point 2 1) (point 2 2) 1) test-grid) (list (point 2 1) (point 1 1)))
|
|
|
|
(check-equal? (boxes-for (line (point 0 0) (point 1 0) 1) test-grid) (list (point 0 0)))
|
|
|
|
(check-equal? (boxes-for (line (point 1 1) (point 2 1) 1) test-grid) (list (point 1 1) (point 1 0)))
|
|
|
|
(check-equal? (boxes-for (line (point 0 5) (point 1 5) 1) test-grid) (list (point 0 4)))
|
|
|
|
(check-equal? (boxes-for (line (point 5 0) (point 5 1) 0) test-grid) (list (point 4 0))))
|
2022-04-03 17:50:25 +00:00
|
|
|
|
2022-04-05 21:05:21 +00:00
|
|
|
(test-case
|
|
|
|
"vertical?"
|
|
|
|
(check-false (vertical? (line (point 2 0) (point 3 0) 0)))
|
|
|
|
(check-true (vertical? (line (point 0 5) (point 0 6) 0))))
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
"horizontal?"
|
|
|
|
(check-true (horizontal? (line (point 2 0) (point 3 0) 0)))
|
|
|
|
(check-false (horizontal? (line (point 0 5) (point 0 6) 0))))
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
"box-in-grid?"
|
|
|
|
(check-true (box-in-grid? test-grid (point 0 0)))
|
|
|
|
(check-true (box-in-grid? test-grid (point 2 4)))
|
|
|
|
(check-false (box-in-grid? test-grid (point 0 5)))
|
|
|
|
(check-false (box-in-grid? test-grid (point 5 0)))
|
|
|
|
(check-false (box-in-grid? test-grid (point -1 3))))
|
|
|
|
|
2022-04-03 17:50:25 +00:00
|
|
|
(test-case
|
|
|
|
"completes-boxes"
|
2022-04-04 11:07:36 +00:00
|
|
|
(define test-grid
|
|
|
|
(grid (list
|
2022-04-03 17:50:25 +00:00
|
|
|
(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 2) (point 0 3) 1)
|
|
|
|
(line (point 0 3) (point 1 3) 1)
|
|
|
|
(line (point 0 2) (point 1 2) 1)
|
|
|
|
(line (point 0 4) (point 0 5) 0)
|
|
|
|
(line (point 0 4) (point 1 4) 1)
|
|
|
|
(line (point 1 4) (point 1 5) 0)
|
|
|
|
(line (point 3 0) (point 4 0) 0)
|
|
|
|
(line (point 3 0) (point 3 1) 1)
|
|
|
|
(line (point 4 0) (point 4 1) 0)
|
|
|
|
(line (point 3 5) (point 4 5) 1)
|
|
|
|
(line (point 3 4) (point 3 5) 0)
|
|
|
|
(line (point 3 4) (point 4 4) 1)
|
|
|
|
(line (point 4 5) (point 5 5) 1)
|
|
|
|
(line (point 4 4) (point 5 4) 0)
|
2022-04-04 11:07:36 +00:00
|
|
|
(line (point 5 4) (point 5 5) 1)) 6 6)) ; all possible unfinished boxes (plus an unfinished double)
|
|
|
|
(check-equal? (completes-boxes test-grid (line (point 0 0) (point 1 0) 0)) 1)
|
|
|
|
(check-equal? (completes-boxes test-grid (line (point 1 2) (point 1 3) 0)) 1)
|
|
|
|
(check-equal? (completes-boxes test-grid (line (point 3 1) (point 4 1) 0)) 1)
|
|
|
|
(check-equal? (completes-boxes test-grid (line (point 0 5) (point 1 5) 0)) 1)
|
|
|
|
(check-equal? (completes-boxes test-grid (line (point 4 4) (point 4 5) 0)) 2)
|
|
|
|
(check-equal? (completes-boxes test-grid (line (point 1 0) (point 2 0) 1)) 0))
|
2022-04-03 17:50:25 +00:00
|
|
|
|
2022-03-30 19:12:43 +00:00
|
|
|
(test-case
|
|
|
|
"valid-move?"
|
2022-04-04 11:07:36 +00:00
|
|
|
(define test-grid (grid (list
|
2022-04-01 16:01:32 +00:00
|
|
|
(line (point 0 0) (point 0 1) 1)
|
|
|
|
(line (point 0 1) (point 0 2) 0)
|
2022-04-04 11:07:36 +00:00
|
|
|
(line (point 3 2) (point 3 3) 0)) 6 6))
|
|
|
|
(check-false (valid-move? (line (point 0 0) (point 0 1) 1) test-grid))
|
|
|
|
(check-true (valid-move? (line (point 0 2) (point 0 3) 0) test-grid)) ; not overwriting existing moves
|
|
|
|
(check-false (valid-move? (line (point 0 2) (point 0 1) 1) test-grid)) ; moving forward
|
|
|
|
(check-false (valid-move? (line (point 0 0) (point 0 2) 1) test-grid)) ; valid length check
|
2022-04-05 21:05:21 +00:00
|
|
|
(check-false (valid-move? (line (point (+ (grid-width test-grid) 1) 0) (point 0 2) 1) test-grid))
|
|
|
|
(check-false (valid-move? (line (point (+ (grid-width test-grid) 1) 0) (point 0 2) 1) test-grid))) ; out of bounds
|
2022-03-30 19:12:43 +00:00
|
|
|
|
|
|
|
(test-case
|
|
|
|
"out-of-bounds?"
|
2022-04-05 10:14:06 +00:00
|
|
|
(check-false (out-of-bounds? (point 0 0) test-grid))
|
|
|
|
(check-false (out-of-bounds? (point 0 (- (grid-width test-grid) 1)) test-grid))
|
|
|
|
(check-true (out-of-bounds? (point (grid-width test-grid) 0) test-grid))
|
|
|
|
(check-true (out-of-bounds? (point -2 0) test-grid))
|
|
|
|
(check-true (out-of-bounds? (point 0 -2) test-grid)))
|
2022-03-31 11:18:48 +00:00
|
|
|
|
|
|
|
(test-case
|
|
|
|
"forwards?"
|
|
|
|
(check-true (forwards? (line (point 0 0) (point 0 1) 1)))
|
|
|
|
(check-true (forwards? (line (point 0 1) (point 1 1) 1)))
|
2022-03-31 13:40:43 +00:00
|
|
|
(check-false (forwards? (line (point 1 1) (point 0 0) 0))))
|
2022-04-01 16:01:32 +00:00
|
|
|
|
2022-04-01 22:11:42 +00:00
|
|
|
(test-case
|
|
|
|
"point+"
|
|
|
|
(check-equal? (point+ (point 0 0) (point 1 2)) (point 1 2))
|
|
|
|
(check-equal? (point+ (point 2 4) (point 5 0)) (point 7 4))
|
|
|
|
(check-equal? (point+ (point 0 0) (point 0 0)) (point 0 0)))
|
|
|
|
|
2022-04-01 16:01:32 +00:00
|
|
|
(test-case
|
|
|
|
"count-square"
|
2022-04-04 11:27:19 +00:00
|
|
|
(check-equal? (count-square (point 0 0) test-grid) 4)
|
|
|
|
(check-equal? (count-square (point 1 0) test-grid) 3)
|
|
|
|
(check-equal? (count-square (point 2 0) test-grid) 2)
|
|
|
|
(check-equal? (count-square (point 3 2) test-grid) 1)
|
|
|
|
(check-equal? (count-square (point 0 4) test-grid) 0))
|
2022-04-03 14:18:59 +00:00
|
|
|
|
|
|
|
(test-case
|
|
|
|
"append-move"
|
2022-04-04 11:07:36 +00:00
|
|
|
(check-equal? (append-move test-grid (line (point 2 2) (point 2 3) 0)) (grid (append
|
|
|
|
(grid-lines test-grid)
|
|
|
|
(list (line (point 2 2) (point 2 3) 0)))
|
|
|
|
(grid-width test-grid) (grid-height test-grid)))
|
|
|
|
(check-equal? (append-move test-grid (line (point 0 0) (point 0 1) 0)) test-grid))
|
2022-04-03 14:18:59 +00:00
|
|
|
|
2022-04-02 21:55:30 +00:00
|
|
|
|
|
|
|
(test-case
|
|
|
|
"valid-moves"
|
2022-04-04 11:07:36 +00:00
|
|
|
(check-equal? (valid-moves test-grid) (list
|
2022-04-02 21:55:30 +00:00
|
|
|
(line (point 0 1) (point 0 2) 1)
|
|
|
|
(line (point 0 2) (point 1 2) 1)
|
|
|
|
(line (point 0 2) (point 0 3) 1)
|
|
|
|
(line (point 0 3) (point 1 3) 1)
|
|
|
|
(line (point 0 3) (point 0 4) 1)
|
|
|
|
(line (point 0 4) (point 1 4) 1)
|
|
|
|
(line (point 0 4) (point 0 5) 1)
|
|
|
|
(line (point 0 5) (point 1 5) 1)
|
|
|
|
(line (point 1 0) (point 2 0) 1)
|
|
|
|
(line (point 1 1) (point 1 2) 1)
|
|
|
|
(line (point 1 2) (point 2 2) 1)
|
|
|
|
(line (point 1 2) (point 1 3) 1)
|
|
|
|
(line (point 1 3) (point 2 3) 1)
|
|
|
|
(line (point 1 3) (point 1 4) 1)
|
|
|
|
(line (point 1 4) (point 2 4) 1)
|
|
|
|
(line (point 1 4) (point 1 5) 1)
|
|
|
|
(line (point 1 5) (point 2 5) 1)
|
|
|
|
(line (point 2 1) (point 3 1) 1)
|
|
|
|
(line (point 2 1) (point 2 2) 1)
|
|
|
|
(line (point 2 2) (point 3 2) 1)
|
|
|
|
(line (point 2 2) (point 2 3) 1)
|
|
|
|
(line (point 2 3) (point 3 3) 1)
|
|
|
|
(line (point 2 3) (point 2 4) 1)
|
|
|
|
(line (point 2 4) (point 3 4) 1)
|
|
|
|
(line (point 2 4) (point 2 5) 1)
|
|
|
|
(line (point 2 5) (point 3 5) 1)
|
|
|
|
(line (point 3 0) (point 4 0) 1)
|
|
|
|
(line (point 3 0) (point 3 1) 1)
|
|
|
|
(line (point 3 1) (point 4 1) 1)
|
|
|
|
(line (point 3 1) (point 3 2) 1)
|
|
|
|
(line (point 3 2) (point 4 2) 1)
|
|
|
|
(line (point 3 2) (point 3 3) 1)
|
|
|
|
(line (point 3 4) (point 3 5) 1)
|
|
|
|
(line (point 3 5) (point 4 5) 1)
|
|
|
|
(line (point 4 0) (point 5 0) 1)
|
|
|
|
(line (point 4 0) (point 4 1) 1)
|
|
|
|
(line (point 4 1) (point 5 1) 1)
|
|
|
|
(line (point 4 1) (point 4 2) 1)
|
|
|
|
(line (point 4 2) (point 5 2) 1)
|
|
|
|
(line (point 4 2) (point 4 3) 1)
|
|
|
|
(line (point 4 3) (point 5 3) 1)
|
|
|
|
(line (point 4 4) (point 5 4) 1)
|
|
|
|
(line (point 4 4) (point 4 5) 1)
|
|
|
|
(line (point 4 5) (point 5 5) 1)
|
|
|
|
(line (point 5 0) (point 5 1) 1)
|
|
|
|
(line (point 5 1) (point 5 2) 1)
|
|
|
|
(line (point 5 2) (point 5 3) 1)
|
|
|
|
(line (point 5 3) (point 5 4) 1)
|
|
|
|
(line (point 5 4) (point 5 5) 1))))
|