|
| 1 | +;;; two-bucket-test.el --- Two Bucket (exercism) -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;;; Commentary: |
| 4 | + |
| 5 | +;;; Code: |
| 6 | + |
| 7 | + |
| 8 | +(load-file "two-bucket.el") |
| 9 | +(declare-function measure "two-bucket.el" (bucket-one bucket-two goal start-bucket)) |
| 10 | + |
| 11 | + |
| 12 | +(ert-deftest measure-using-bucket-one-of-size-3-and-bucket-two-of-size-5-start-with-bucket-one () |
| 13 | + ;; Function under test: measure |
| 14 | + ;; Input: {"bucketOne":3,"bucketTwo":5,"goal":1,"startBucket":"one"} |
| 15 | + ;; Expected: {"moves":4,"goalBucket":"one","otherBucket":5} |
| 16 | + (should (equal (measure 3 5 1 'one) '(4 one 5)))) |
| 17 | + |
| 18 | + |
| 19 | +(ert-deftest measure-using-bucket-one-of-size-3-and-bucket-two-of-size-5-start-with-bucket-two () |
| 20 | + ;; Function under test: measure |
| 21 | + ;; Input: {"bucketOne":3,"bucketTwo":5,"goal":1,"startBucket":"two"} |
| 22 | + ;; Expected: {"moves":8,"goalBucket":"two","otherBucket":3} |
| 23 | + (should (equal (measure 3 5 1 'two) '(8 two 3)))) |
| 24 | + |
| 25 | + |
| 26 | +(ert-deftest measure-using-bucket-one-of-size-7-and-bucket-two-of-size-11-start-with-bucket-one () |
| 27 | + ;; Function under test: measure |
| 28 | + ;; Input: {"bucketOne":7,"bucketTwo":11,"goal":2,"startBucket":"one"} |
| 29 | + ;; Expected: {"moves":14,"goalBucket":"one","otherBucket":11} |
| 30 | + (should (equal (measure 7 11 2 'one) '(14 one 11)))) |
| 31 | + |
| 32 | + |
| 33 | +(ert-deftest measure-using-bucket-one-of-size-7-and-bucket-two-of-size-11-start-with-bucket-two () |
| 34 | + ;; Function under test: measure |
| 35 | + ;; Input: {"bucketOne":7,"bucketTwo":11,"goal":2,"startBucket":"two"} |
| 36 | + ;; Expected: {"moves":18,"goalBucket":"two","otherBucket":7} |
| 37 | + (should (equal (measure 7 11 2 'two) '(18 two 7)))) |
| 38 | + |
| 39 | + |
| 40 | +(ert-deftest measure-one-step-using-bucket-one-of-size-1-and-bucket-two-of-size-3-start-with-bucket-two () |
| 41 | + ;; Function under test: measure |
| 42 | + ;; Input: {"bucketOne":1,"bucketTwo":3,"goal":3,"startBucket":"two"} |
| 43 | + ;; Expected: {"moves":1,"goalBucket":"two","otherBucket":0} |
| 44 | + (should (equal (measure 1 3 3 'two) '(1 two 0)))) |
| 45 | + |
| 46 | + |
| 47 | +(ert-deftest measure-using-bucket-one-of-size-2-and-bucket-two-of-size-3-start-with-bucket-one-and-end-with-bucket-two () |
| 48 | + ;; Function under test: measure |
| 49 | + ;; Input: {"bucketOne":2,"bucketTwo":3,"goal":3,"startBucket":"one"} |
| 50 | + ;; Expected: {"moves":2,"goalBucket":"two","otherBucket":2} |
| 51 | + (should (equal (measure 2 3 3 'one) '(2 two 2)))) |
| 52 | + |
| 53 | + |
| 54 | +(ert-deftest not-possible-to-reach-the-goal () |
| 55 | + ;; Function under test: measure |
| 56 | + ;; Input: {"bucketOne":6,"bucketTwo":15,"goal":5,"startBucket":"one"} |
| 57 | + ;; Expected: {"error":"impossible"} |
| 58 | + (should-error (measure 6 15 5 'one) :type 'goal-not-possible)) |
| 59 | + |
| 60 | + |
| 61 | +(ert-deftest with-the-same-buckets-but-a-different-goal-then-it-is-possible () |
| 62 | + ;; Function under test: measure |
| 63 | + ;; Input: {"bucketOne":6,"bucketTwo":15,"goal":9,"startBucket":"one"} |
| 64 | + ;; Expected: {"moves":10,"goalBucket":"two","otherBucket":0} |
| 65 | + (should (equal (measure 6 15 9 'one) '(10 two 0)))) |
| 66 | + |
| 67 | + |
| 68 | +(ert-deftest goal-larger-than-both-buckets-is-impossible () |
| 69 | + ;; Function under test: measure |
| 70 | + ;; Input: {"bucketOne":5,"bucketTwo":7,"goal":8,"startBucket":"one"} |
| 71 | + ;; Expected: {"error":"impossible"} |
| 72 | + (should-error (measure 5 7 8 'one) :type 'goal-not-possible)) |
| 73 | + |
| 74 | + |
| 75 | +(provide 'two-bucket-test) |
| 76 | +;;; two-bucket-test.el ends here |
| 77 | + |
0 commit comments