-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
two-bucket-test.lisp
101 lines (87 loc) · 4.01 KB
/
two-bucket-test.lisp
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
;; Ensures that two-bucket.lisp and the testing library are always loaded
(eval-when (:compile-toplevel :load-toplevel :execute)
(load "two-bucket")
(quicklisp-client:quickload :fiveam))
;; Defines the testing package with symbols from two-bucket and FiveAM in scope
;; The `run-tests` function is exported for use by both the user and test-runner
(defpackage :two-bucket-test
(:use :cl :fiveam)
(:export :run-tests))
;; Enter the testing package
(in-package :two-bucket-test)
;; Define and enter a new FiveAM test-suite
(def-suite* two-bucket-suite)
(defun equal-alists (alist-one alist-two)
(and (subsetp alist-one alist-two :test 'equal)
(subsetp alist-two alist-one :test 'equal)))
(test measure-using-bucket-one-of-size-3-and-bucket-two-of-size-5-start-with-bucket-one
(let* ((bucket-one 3)
(bucket-two 5)
(goal 1)
(start-bucket :one)
(result '((:moves . 4) (:goal-bucket . :one) (:other-bucket . 5)))
(output (two-bucket:measure bucket-one bucket-two goal start-bucket)))
(is (equal-alists result output))))
(test measure-using-bucket-one-of-size-3-and-bucket-two-of-size-5-start-with-bucket-two
(let* ((bucket-one 3)
(bucket-two 5)
(goal 1)
(start-bucket :two)
(result '((:moves . 8) (:goal-bucket . :two) (:other-bucket . 3)))
(output (two-bucket:measure bucket-one bucket-two goal start-bucket)))
(is (equal-alists result output))))
(test measure-using-bucket-one-of-size-7-and-bucket-two-of-size-11-start-with-bucket-one
(let* ((bucket-one 7)
(bucket-two 11)
(goal 2)
(start-bucket :one)
(result '((:moves . 14) (:goal-bucket . :one) (:other-bucket . 11)))
(output (two-bucket:measure bucket-one bucket-two goal start-bucket)))
(is (equal-alists result output))))
(test measure-using-bucket-one-of-size-7-and-bucket-two-of-size-11-start-with-bucket-two
(let* ((bucket-one 7)
(bucket-two 11)
(goal 2)
(start-bucket :two)
(result '((:moves . 18) (:goal-bucket . :two) (:other-bucket . 7)))
(output (two-bucket:measure bucket-one bucket-two goal start-bucket)))
(is (equal-alists result output))))
(test measure-one-step-using-bucket-one-of-size-1-and-bucket-two-of-size-3-start-with-bucket-two
(let* ((bucket-one 1)
(bucket-two 3)
(goal 3)
(start-bucket :two)
(result '((:moves . 1) (:goal-bucket . :two) (:other-bucket . 0)))
(output (two-bucket:measure bucket-one bucket-two goal start-bucket)))
(is (equal-alists result output))))
(test measure-using-bucket-one-of-size-2-and-bucket-two-of-size-3-start-with-bucket-one-and-end-with-bucket-two
(let* ((bucket-one 2)
(bucket-two 3)
(goal 3)
(start-bucket :one)
(result '((:moves . 2) (:goal-bucket . :two) (:other-bucket . 2)))
(output (two-bucket:measure bucket-one bucket-two goal start-bucket)))
(is (equal-alists result output))))
(test not-possible-to-reach-the-goal
(let ((bucket-one 6)
(bucket-two 15)
(goal 5)
(start-bucket :one))
(is (equal NIL (two-bucket:measure bucket-one bucket-two goal start-bucket)))))
(test with-the-same-buckets-but-a-different-goal-then-it-is-possible
(let* ((bucket-one 6)
(bucket-two 15)
(goal 9)
(start-bucket :one)
(result '((:moves . 10) (:goal-bucket . :two) (:other-bucket . 0)))
(output (two-bucket:measure bucket-one bucket-two goal start-bucket)))
(is (equal-alists result output))))
(test goal-larger-than-both-buckets-is-impossible
(let ((bucket-one 5)
(bucket-two 7)
(goal 8)
(start-bucket :one))
(is (equal NIL (two-bucket:measure bucket-one bucket-two goal start-bucket)))))
(defun run-tests (&optional (test-or-suite 'two-bucket-suite))
"Provides human readable results of test run. Default to entire suite."
(run! test-or-suite))