summaryrefslogtreecommitdiff
path: root/perfectly-spherical-houses-in-a-vacuum/pshiav-test.scm
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2024-06-10 12:26:20 -0600
committerbd <bdunahu@operationnull.com>2024-06-10 12:26:20 -0600
commit58ee9f48c4c90352bccdb1cc88d7b9ef923f9216 (patch)
treea6ea3f2e215f446b344aef218e695721edb5bb7b /perfectly-spherical-houses-in-a-vacuum/pshiav-test.scm
parentefb4865c81bfef747428303d5388fb1889db5769 (diff)
AoC 2015.3 p1+2
Diffstat (limited to 'perfectly-spherical-houses-in-a-vacuum/pshiav-test.scm')
-rw-r--r--perfectly-spherical-houses-in-a-vacuum/pshiav-test.scm83
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")