summaryrefslogtreecommitdiff
path: root/09/test.scm
blob: 6d232daa4134d0491de75e329d0b3d318ee959e1 (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
(import (chezscheme))

; Where the magic happens
(import (lib))

; My quick-and-dirty unit testing framework (copied for each day)
(define (run-test name proc input expected)
  (let ((result (proc input)))
    (if (equal? result expected)
      (printf "\x1b;[32;1mPASS\x1b;[0m: ~a\n"
              name)
      (printf "\x1b;[31;1mFAIL\x1b;[0m: ~a: got ~a, expected ~a\n"
              name result expected))))

(printf "Part 1 tests:\n")

(define (test-part1 name input expected)
  (run-test name solve-part1 input expected))

(test-part1 "part 1 example 1"
            "{}" 1)

(test-part1 "part 1 example 2"
            "{{{}}}" 6)

(test-part1 "part 1 example 3"
            "{{},{}}" 5)

(test-part1 "part 1 example 4"
            "{{{},{},{{}}}}" 16)

(test-part1 "part 1 example 5"
            "{<a>,<a>,<a>,<a>}" 1)

(test-part1 "part 1 example 6"
            "{{<ab>},{<ab>},{<ab>},{<ab>}}" 9)

(test-part1 "part 1 example 7"
            "{{<!!>},{<!!>},{<!!>},{<!!>}}" 9)

(test-part1 "part 1 example 8"
            "{{<a!>},{<a!>},{<a!>},{<ab>}}" 3)

(printf "Part 2 tests:\n")

(define (test-part2 name input expected)
  (run-test name solve-part2 input expected))

(test-part2 "part 2 example 1"
            "{<>}" 0)

(test-part2 "part 2 example 2"
            "{<random characters>}" 17)

(test-part2 "part 2 example 3"
            "{<<<<>}" 3)

(test-part2 "part 2 example 4"
            "{<{!>}>}" 2)

(test-part2 "part 2 example 5"
            "{<!!>}" 0)

(test-part2 "part 2 example 6"
            "{<!!!>>}" 0)

(test-part2 "part 2 example 7"
            "{<{o\"i!a,<{i<a>}" 10)