84 lines
3.4 KiB
Racket
84 lines
3.4 KiB
Racket
#lang racket
|
|
|
|
(require rackunit "main.rkt")
|
|
|
|
(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))))
|
|
|
|
(test-case
|
|
"out-of-bounds?"
|
|
(check-false (out-of-bounds? (point 0 0)))
|
|
(check-false (out-of-bounds? (point 0 (- GRID-WIDTH 1))))
|
|
(check-true (out-of-bounds? (point GRID-WIDTH 0)))
|
|
(check-true (out-of-bounds? (point -2 0)))
|
|
(check-true (out-of-bounds? (point 0 -2))))
|
|
|
|
(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)))
|
|
(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
|
|
(check-false (valid-move? (line (point 0 0) (point 0 2) 1) grid)) ; valid length check
|
|
(check-false (valid-move? (line (point (+ GRID-WIDTH 1) 0) (point 0 2) 1) grid))
|
|
(check-false (valid-move? (line (point (+ GRID-WIDTH 1) 0) (point 0 2) 1) grid))) ; out of bounds
|
|
|
|
(test-case
|
|
"out-of-bounds?"
|
|
(check-false (out-of-bounds? (point 0 0)))
|
|
(check-false (out-of-bounds? (point 0 (- GRID-WIDTH 1))))
|
|
(check-true (out-of-bounds? (point GRID-WIDTH 0)))
|
|
(check-true (out-of-bounds? (point -2 0)))
|
|
(check-true (out-of-bounds? (point 0 -2))))
|
|
|
|
(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)))
|
|
(check-false (forwards? (line (point 1 1) (point 0 0) 0))))
|
|
|
|
(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)))
|
|
|
|
(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 1 0) grid) 3)
|
|
(check-equal? (count-square (point 2 0) grid) 2)
|
|
(check-equal? (count-square (point 3 2) grid) 1)
|
|
(check-equal? (count-square (point 0 4) grid) 0)
|
|
) |