1
exercism fetch ecmascript two-bucket

two-bucket.spec.js

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
import TwoBucket from './two-bucket';

describe('TwoBucket', () => {
  describe('works for input of 3, 5, 1', () => {
    const buckOne = 3;
    const buckTwo = 5;
    const goal = 1;

    test('starting with bucket one', () => {
      const starterBuck = 'one'; // indicates which bucket to fill first
      const twoBucket = new TwoBucket(buckOne, buckTwo, goal, starterBuck);
      expect(twoBucket.moves()).toEqual(4); // includes the first fill
      expect(twoBucket.goalBucket).toEqual('one'); // which bucket should end up with the desired # of liters
      expect(twoBucket.otherBucket).toEqual(5); // leftover value in the "other" bucket once the goal has been reached
    });

    xtest('starting 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);
    });
  });

  describe('works for input of 7, 11, 2', () => {
    const buckOne = 7;
    const buckTwo = 11;
    const goal = 2;

    xtest('starting 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);
    });

    xtest('starting 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);
    });
  });
});