summaryrefslogtreecommitdiff
path: root/trebuchet/t-test.scm
blob: 72fff8d74ef7d04d73a9df00b839411aa47bdd37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
;; -*- 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")