;; -*- compile-command: "guile -L . t-test.scm"; -*- (use-modules (srfi srfi-64) (t)) (test-begin "harness") (test-equal "12 returns 12" 12 (parse-int (string->list "12"))) (test-equal "1abc2 returns 12" 12 (parse-int (string->list "1abc2"))) (test-equal "treb7uchet returns 77" 77 (parse-int (string->list "treb7uchet"))) (test-equal "sum 4 lines" 142 (t " 1abc2 pqr3stu8vwx a1b2c3d4e5f treb7uchet" #f)) (test-assert "f o u r 2 6 9 starts with '4'" (starts-with? '(f o u r 2 6 9) '(4 . ((f o u r) . 4)))) (test-assert "f o u r 2 6 9 does not start with '9'" (not (starts-with? '(f o u r 2 6 9) '(9 . ((n i n e) . 4))))) (test-assert "comparisons that are longer do not crash" (not (starts-with? '(f o u r) '(3 . ((t h r e e) . 5))))) (test-equal "replace f o u r with 4" '(4 r 2 6 9) (replace-elements '(f o u r 2 6 9) '(4 . ((f o u r) . 4)))) (test-equal "finds true at pos 0" 0 (find-true '(#t #t #f))) (test-equal "finds true at pos 1" 1 (find-true '(#f #t #f))) (test-assert "true missing" (not (find-true '(#f #f #f)))) (test-equal "converts no numbers" '(1 a b c 2) (spelt->numbers '(1 a b c 2))) (test-equal "converts single nine" '(#\9 #\e) (spelt->numbers '(#\n #\i #\n #\e))) (test-equal "does not convert false nine" '(#\n #\i #\9 #\n #\e) (spelt->numbers '(#\n #\i #\9 #\n #\e))) (test-equal "convert two1nine" '(#\2 #\o #\1 #\9 #\e) (spelt->numbers '(#\t #\w #\o #\1 #\n #\i #\n #\e))) (test-equal "convert eighttwothree" '(#\8 #\t #\2 #\o #\3 #\e) (spelt->numbers '(#\e #\i #\g #\h #\t #\t #\w #\o #\t #\h #\r #\e #\e))) (test-equal "convert abcone2threexyz" '(#\a #\b #\c #\1 #\e #\2 #\3 #\e #\x #\y #\z) (spelt->numbers '(#\a #\b #\c #\o #\n #\e #\2 #\t #\h #\r #\e #\e #\x #\y #\z))) (test-equal "convert pqr3stu8nine" '(#\p #\q #\r #\3 #\s #\t #\u #\8 #\9 #\e) (spelt->numbers '(#\p #\q #\r #\3 #\s #\t #\u #\8 #\n #\i #\n #\e))) ;; ;; NOTE: an assumption is being made here! ;; ;; should the eight have been converted? ;; ;; will it matter? ;; turns out---it does matter :( ;; (test-equal "convert zoneight234" ;; '(#\z #\1 #\i #\g #\h #\t #\2 #\3 #\4) ;; (spelt->numbers '(#\z #\o #\n #\e #\i #\g #\h #\t #\2 #\3 #\4))) (test-equal "convert zoneight234" '(#\z #\1 #\8 #\t #\2 #\3 #\4) (spelt->numbers '(#\z #\o #\n #\e #\i #\g #\h #\t #\2 #\3 #\4))) (test-equal "sum 7 lines convert" 281 (t " two1nine eightwothree abcone2threexyz xtwone3four 4nineeightseven2 zoneight234 7pqrstsixteen" #t)) (test-end "harness")