-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathtwo-bucket.test.ts
97 lines (85 loc) · 3.32 KB
/
two-bucket.test.ts
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
import { describe, xdescribe, it, expect, xit } from '@jest/globals'
import { TwoBucket } from './two-bucket.ts'
describe('TwoBucket', () => {
describe('Measure using bucket one of size 3 and bucket two of size 5', () => {
const buckOne = 3
const buckTwo = 5
const goal = 1
it('start with bucket one', () => {
// indicates which bucket to fill first
const starterBuck = 'one'
const twoBucket = new TwoBucket(buckOne, buckTwo, goal, starterBuck)
// includes the first fill
expect(twoBucket.moves()).toEqual(4)
// which bucket should end up with the desired # of liters
expect(twoBucket.goalBucket).toEqual('one')
// leftover value in the "other" bucket once the goal has been reached
expect(twoBucket.otherBucket).toEqual(5)
})
xit('start with bucket two', () => {
const starterBuck = 'two'
const twoBucket = new TwoBucket(buckOne, buckTwo, goal, starterBuck)
expect(twoBucket.moves()).toEqual(8)
expect(twoBucket.goalBucket).toEqual('two')
expect(twoBucket.otherBucket).toEqual(3)
})
})
xdescribe('Measure using bucket one of size 7 and bucket two of size 11', () => {
const buckOne = 7
const buckTwo = 11
const goal = 2
xit('start with bucket one', () => {
const starterBuck = 'one'
const twoBucket = new TwoBucket(buckOne, buckTwo, goal, starterBuck)
expect(twoBucket.moves()).toEqual(14)
expect(twoBucket.goalBucket).toEqual('one')
expect(twoBucket.otherBucket).toEqual(11)
})
xit('start with bucket two', () => {
const starterBuck = 'two'
const twoBucket = new TwoBucket(buckOne, buckTwo, goal, starterBuck)
expect(twoBucket.moves()).toEqual(18)
expect(twoBucket.goalBucket).toEqual('two')
expect(twoBucket.otherBucket).toEqual(7)
})
})
xdescribe('Measure one step using bucket one of size 1 and bucket two of size 3', () => {
xit('start with bucket two', () => {
const twoBucket = new TwoBucket(1, 3, 3, 'two')
expect(twoBucket.moves()).toEqual(1)
expect(twoBucket.goalBucket).toEqual('two')
expect(twoBucket.otherBucket).toEqual(0)
})
})
xdescribe('Measure using bucket one of size 2 and bucket two of size 3', () => {
xit('start with bucket one and end with bucket two', () => {
const twoBucket = new TwoBucket(2, 3, 3, 'one')
expect(twoBucket.moves()).toEqual(2)
expect(twoBucket.goalBucket).toEqual('two')
expect(twoBucket.otherBucket).toEqual(2)
})
})
xdescribe('Reachability', () => {
const buckOne = 6
const buckTwo = 15
const starterBuck = 'one'
xit('Not possible to reach the goal', () => {
const goal = 5
const twoBucket = new TwoBucket(buckOne, buckTwo, goal, starterBuck)
expect(() => twoBucket.moves()).toThrow()
})
xit('With the same buckets but a different goal, then it is possible', () => {
const goal = 9
const twoBucket = new TwoBucket(buckOne, buckTwo, goal, starterBuck)
expect(twoBucket.moves()).toEqual(10)
expect(twoBucket.goalBucket).toEqual('two')
expect(twoBucket.otherBucket).toEqual(0)
})
})
xdescribe('Goal larger than both buckets', () => {
xit('Is impossible', () => {
const twoBucket = new TwoBucket(5, 7, 8, 'one')
expect(() => twoBucket.moves()).toThrow()
})
})
})