diff options
Diffstat (limited to 'perfectly-spherical-houses-in-a-vacuum/pshiav-test.scm')
-rw-r--r-- | perfectly-spherical-houses-in-a-vacuum/pshiav-test.scm | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/perfectly-spherical-houses-in-a-vacuum/pshiav-test.scm b/perfectly-spherical-houses-in-a-vacuum/pshiav-test.scm new file mode 100644 index 0000000..a27dec4 --- /dev/null +++ b/perfectly-spherical-houses-in-a-vacuum/pshiav-test.scm @@ -0,0 +1,83 @@ +;; -*- compile-command: "guile -L . pshiav-test.scm"; -*- +(use-modules (srfi srfi-64) + (pshiav)) + +(test-begin "harness") + + +(define coordinate-accumulator + (add-coordinates)) + +(test-equal "don't move" + '((0 . 0) (0 . 0)) + (coordinate-accumulator '(0 . 0))) + +(set! coordinate-accumulator + (add-coordinates)) + +(test-equal "move up" + '((0 . 1) (0 . 0)) + (coordinate-accumulator '(0 . 1))) + +(set! coordinate-accumulator + (add-coordinates)) + +(test-equal "move up twice" + '((0 . 2) (0 . 1) (0 . 0)) + (begin (coordinate-accumulator '(0 . 1)) + (coordinate-accumulator '(0 . 1)))) + +(test-equal "up maps to +y" + '(0 . 1) + (direction->pair #\^)) + +(test-equal "right maps to +x" + '(1 . 0) + (direction->pair #\>)) + +(test-equal "down maps to -y" + '(0 . -1) + (direction->pair #\v)) + +(test-equal "left maps to -x" + '(-1 . 0) + (direction->pair #\<)) + +(test-equal "? maps to no change" + '(0 . 0) + (direction->pair #\?)) + +(test-equal "empty input visits one place" + 1 + (pshiav "" 1)) + +(test-equal "down once visits two places" + 2 + (pshiav "v" 1)) + +(test-equal "down twice visits three places" + 3 + (pshiav "vv" 1)) + +(test-equal "down twice, up once visits three places" + 3 + (pshiav "vv^" 1)) + +(test-equal "up down visits three with two visitors" + 3 + (pshiav "^v" 2)) + +(test-equal "up right down left visits three with two visitors" + 3 + (pshiav "^>v<" 2)) + +(test-equal "opposite instructions maximizes visits with two" + 11 + (pshiav "^v^v^v^v^v" 2)) + +(test-equal "opposite instructions maximizes visits with three" + 16 + (pshiav "^v>^v>^v>^v>^v>" 3)) + + +(test-end "harness") |