|
1 | | -local two_bucket = require 'two-bucket' |
| 1 | +local two_bucket = require('two-bucket') |
2 | 2 |
|
3 | | --- LuaFormatter off |
4 | 3 | describe('two-bucket', function() |
5 | 4 | it('measure using bucket one of size 3 and bucket two of size 5 - start with bucket one', function() |
6 | 5 | assert.are.same(two_bucket.measure({ |
7 | | - bucket_one_capacity = 3, |
8 | | - bucket_two_capacity = 5, |
9 | | - goal_volume = 1, |
10 | | - start_bucket = 1 |
| 6 | + bucket_one_capacity = 3, -- |
| 7 | + bucket_two_capacity = 5, -- |
| 8 | + goal_volume = 1, -- |
| 9 | + start_bucket = 1 -- |
11 | 10 | }), { |
12 | | - moves = 4, |
13 | | - other_bucket_volume = 5, |
14 | | - goal_bucket_number = 1 |
| 11 | + moves = 4, -- |
| 12 | + other_bucket_volume = 5, -- |
| 13 | + goal_bucket_number = 1 -- |
15 | 14 | }) |
16 | 15 | end) |
17 | 16 |
|
18 | 17 | it('measure using bucket one of size 3 and bucket two of size 5 - start with bucket two', function() |
19 | 18 | assert.are.same(two_bucket.measure({ |
20 | | - bucket_one_capacity = 3, |
21 | | - bucket_two_capacity = 5, |
22 | | - goal_volume = 1, |
23 | | - start_bucket = 2 |
| 19 | + bucket_one_capacity = 3, -- |
| 20 | + bucket_two_capacity = 5, -- |
| 21 | + goal_volume = 1, -- |
| 22 | + start_bucket = 2 -- |
24 | 23 | }), { |
25 | | - moves = 8, |
26 | | - other_bucket_volume = 3, |
27 | | - goal_bucket_number = 2 |
| 24 | + moves = 8, -- |
| 25 | + other_bucket_volume = 3, -- |
| 26 | + goal_bucket_number = 2 -- |
28 | 27 | }) |
29 | 28 | end) |
30 | 29 |
|
31 | 30 | it('measure using bucket one of size 7 and bucket two of size 11 - start with bucket one', function() |
32 | 31 | assert.are.same(two_bucket.measure({ |
33 | | - bucket_one_capacity = 7, |
34 | | - bucket_two_capacity = 11, |
35 | | - goal_volume = 2, |
36 | | - start_bucket = 1 |
| 32 | + bucket_one_capacity = 7, -- |
| 33 | + bucket_two_capacity = 11, -- |
| 34 | + goal_volume = 2, -- |
| 35 | + start_bucket = 1 -- |
37 | 36 | }), { |
38 | | - moves = 14, |
39 | | - other_bucket_volume = 11, |
40 | | - goal_bucket_number = 1 |
| 37 | + moves = 14, -- |
| 38 | + other_bucket_volume = 11, -- |
| 39 | + goal_bucket_number = 1 -- |
41 | 40 | }) |
42 | 41 | end) |
43 | 42 |
|
44 | 43 | it('measure using bucket one of size 7 and bucket two of size 11 - start with bucket two', function() |
45 | 44 | assert.are.same(two_bucket.measure({ |
46 | | - bucket_one_capacity = 7, |
47 | | - bucket_two_capacity = 11, |
48 | | - goal_volume = 2, |
49 | | - start_bucket = 2 |
| 45 | + bucket_one_capacity = 7, -- |
| 46 | + bucket_two_capacity = 11, -- |
| 47 | + goal_volume = 2, -- |
| 48 | + start_bucket = 2 -- |
50 | 49 | }), { |
51 | | - moves = 18, |
52 | | - other_bucket_volume = 7, |
53 | | - goal_bucket_number = 2 |
| 50 | + moves = 18, -- |
| 51 | + other_bucket_volume = 7, -- |
| 52 | + goal_bucket_number = 2 -- |
54 | 53 | }) |
55 | 54 | end) |
56 | 55 |
|
57 | 56 | it('measure one step using bucket one of size 1 and bucket two of size 3 - start with bucket two', function() |
58 | 57 | assert.are.same(two_bucket.measure({ |
59 | | - bucket_one_capacity = 1, |
60 | | - bucket_two_capacity = 3, |
61 | | - goal_volume = 3, |
62 | | - start_bucket = 2 |
| 58 | + bucket_one_capacity = 1, -- |
| 59 | + bucket_two_capacity = 3, -- |
| 60 | + goal_volume = 3, -- |
| 61 | + start_bucket = 2 -- |
63 | 62 | }), { |
64 | | - moves = 1, |
65 | | - other_bucket_volume = 0, |
66 | | - goal_bucket_number = 2 |
| 63 | + moves = 1, -- |
| 64 | + other_bucket_volume = 0, -- |
| 65 | + goal_bucket_number = 2 -- |
67 | 66 | }) |
68 | 67 | end) |
69 | 68 |
|
70 | | - it('measure using bucket one of size 2 and bucket two of size 3 - start with bucket one and end with bucket two', function() |
| 69 | + it('measure using bucket one of size 2 and bucket two of size 3 - start with bucket one and end with bucket two', |
| 70 | + function() |
71 | 71 | assert.are.same(two_bucket.measure({ |
72 | | - bucket_one_capacity = 2, |
73 | | - bucket_two_capacity = 3, |
74 | | - goal_volume = 3, |
75 | | - start_bucket = 1 |
| 72 | + bucket_one_capacity = 2, -- |
| 73 | + bucket_two_capacity = 3, -- |
| 74 | + goal_volume = 3, -- |
| 75 | + start_bucket = 1 -- |
76 | 76 | }), { |
77 | | - moves = 2, |
78 | | - other_bucket_volume = 2, |
79 | | - goal_bucket_number = 2 |
| 77 | + moves = 2, -- |
| 78 | + other_bucket_volume = 2, -- |
| 79 | + goal_bucket_number = 2 -- |
| 80 | + }) |
| 81 | + end) |
| 82 | + |
| 83 | + it('measure using bucket one much bigger than bucket two', function() |
| 84 | + assert.are.same(two_bucket.measure({ |
| 85 | + bucket_one_capacity = 5, -- |
| 86 | + bucket_two_capacity = 1, -- |
| 87 | + goal_volume = 2, -- |
| 88 | + start_bucket = 1 -- |
| 89 | + }), { |
| 90 | + moves = 6, -- |
| 91 | + other_bucket_volume = 1, -- |
| 92 | + goal_bucket_number = 1 -- |
| 93 | + }) |
| 94 | + end) |
| 95 | + |
| 96 | + it('measure using bucket one much smaller than bucket two', function() |
| 97 | + assert.are.same(two_bucket.measure({ |
| 98 | + bucket_one_capacity = 3, -- |
| 99 | + bucket_two_capacity = 15, -- |
| 100 | + goal_volume = 9, -- |
| 101 | + start_bucket = 1 -- |
| 102 | + }), { |
| 103 | + moves = 6, -- |
| 104 | + other_bucket_volume = 0, -- |
| 105 | + goal_bucket_number = 2 -- |
80 | 106 | }) |
81 | 107 | end) |
82 | 108 |
|
83 | 109 | it('not possible to reach the goal', function() |
84 | 110 | assert.has_error(function() |
85 | 111 | two_bucket.measure({ |
86 | | - bucket_one_capacity = 6, |
87 | | - bucket_two_capacity = 15, |
88 | | - goal_volume = 5, |
89 | | - start_bucket = 1 |
| 112 | + bucket_one_capacity = 6, -- |
| 113 | + bucket_two_capacity = 15, -- |
| 114 | + goal_volume = 5, -- |
| 115 | + start_bucket = 1 -- |
90 | 116 | }) |
91 | 117 | end) |
92 | 118 | end) |
93 | 119 |
|
94 | 120 | it('with the same buckets but a different goal, then it is possible', function() |
95 | 121 | assert.are.same(two_bucket.measure({ |
96 | | - bucket_one_capacity = 6, |
97 | | - bucket_two_capacity = 15, |
98 | | - goal_volume = 9, |
99 | | - start_bucket = 1 |
| 122 | + bucket_one_capacity = 6, -- |
| 123 | + bucket_two_capacity = 15, -- |
| 124 | + goal_volume = 9, -- |
| 125 | + start_bucket = 1 -- |
100 | 126 | }), { |
101 | | - moves = 10, |
102 | | - other_bucket_volume = 0, |
103 | | - goal_bucket_number = 2 |
| 127 | + moves = 10, -- |
| 128 | + other_bucket_volume = 0, -- |
| 129 | + goal_bucket_number = 2 -- |
104 | 130 | }) |
105 | 131 | end) |
106 | 132 |
|
107 | 133 | it('goal larger than both buckets is impossible', function() |
108 | 134 | assert.has_error(function() |
109 | 135 | two_bucket.measure({ |
110 | | - bucket_one_capacity = 5, |
111 | | - bucket_two_capacity = 7, |
112 | | - goal_volume = 8, |
113 | | - start_bucket = 1 |
| 136 | + bucket_one_capacity = 5, -- |
| 137 | + bucket_two_capacity = 7, -- |
| 138 | + goal_volume = 8, -- |
| 139 | + start_bucket = 1 -- |
114 | 140 | }) |
115 | 141 | end) |
116 | 142 | end) |
117 | 143 | end) |
118 | | --- LuaFormatter on |
|
0 commit comments