54 lines
2.3 KiB
Racket
54 lines
2.3 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 board (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) board))
|
|
(check-true (valid-move? (line (point 0 2) (point 0 3) 0) board)) ; not overwriting existing moves
|
|
(check-false (valid-move? (line (point 0 2) (point 0 1) 1) board)) ; moving forward
|
|
(check-false (valid-move? (line (point 0 0) (point 0 2) 1) board)) ; valid length check
|
|
(check-false (valid-move? (line (point (+ GRID-WIDTH 1) 0) (point 0 2) 1) board))
|
|
(check-false (valid-move? (line (point (+ GRID-WIDTH 1) 0) (point 0 2) 1) board))) ; 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)))) |