1
exercism fetch ecmascript sublist

sublist.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import List from './sublist';


describe('sublist', () => {

  test('two empty lists are equal', () => {
    const listOne = new List();
    const listTwo = new List();

    expect(listOne.compare(listTwo)).toEqual('EQUAL');
  });

  xtest('an empty list is a sublist of a non-empty list', () => {
    const listOne = new List();
    const listTwo = new List([1, 2, 3]);

    expect(listOne.compare(listTwo)).toEqual('SUBLIST');
  });

  xtest('non empty list contains empty list', () => {
    const listOne = new List([1, 2, 3]);
    const listTwo = new List();

    expect(listOne.compare(listTwo)).toEqual('SUPERLIST');
  });

  xtest('a non-empty list equals itself', () => {
    const listOne = new List([1, 2, 3]);
    const listTwo = new List([1, 2, 3]);

    expect(listOne.compare(listTwo)).toEqual('EQUAL');
  });

  xtest('two different lists are unequal', () => {
    const listOne = new List([1, 2, 3]);
    const listTwo = new List([2, 3, 4]);

    expect(listOne.compare(listTwo)).toEqual('UNEQUAL');
  });

  xtest('false start', () => {
    const listOne = new List([1, 2, 5]);
    const listTwo = new List([0, 1, 2, 3, 1, 2, 5, 6]);

    expect(listOne.compare(listTwo)).toEqual('SUBLIST');

  });

  xtest('consecutive', () => {
    const listOne = new List([1, 1, 2]);
    const listTwo = new List([0, 1, 1, 1, 2, 1, 2]);

    expect(listOne.compare(listTwo)).toEqual('SUBLIST');
  });

  xtest('sublist at start', () => {
    const listOne = new List([0, 1, 2]);
    const listTwo = new List([0, 1, 2, 3, 4, 5]);

    expect(listOne.compare(listTwo)).toEqual('SUBLIST');
  });

  xtest('sublist in middle', () => {
    const listOne = new List([2, 3, 4]);
    const listTwo = new List([0, 1, 2, 3, 4, 5]);

    expect(listOne.compare(listTwo)).toEqual('SUBLIST');
  });

  xtest('sublist at end', () => {
    const listOne = new List([3, 4, 5]);
    const listTwo = new List([0, 1, 2, 3, 4, 5]);

    expect(listOne.compare(listTwo)).toEqual('SUBLIST');
  });

  xtest('at start of superlist', () => {
    const listOne = new List([0, 1, 2, 3, 4, 5]);
    const listTwo = new List([0, 1, 2]);

    expect(listOne.compare(listTwo)).toEqual('SUPERLIST');
  });

  xtest('in middle of superlist', () => {
    const listOne = new List([0, 1, 2, 3, 4, 5]);
    const listTwo = new List([2, 3]);

    expect(listOne.compare(listTwo)).toEqual('SUPERLIST');
  });

  xtest('at end of superlist', () => {
    const listOne = new List([0, 1, 2, 3, 4, 5]);
    const listTwo = new List([3, 4, 5]);

    expect(listOne.compare(listTwo)).toEqual('SUPERLIST');
  });

  xtest('first list missing element from second list', () => {
    const listOne = new List([1, 3]);
    const listTwo = new List([1, 2, 3]);

    expect(listOne.compare(listTwo)).toEqual('UNEQUAL');
  });

  xtest('second list missing element from first list', () => {
    const listOne = new List([1, 2, 3]);
    const listTwo = new List([1, 3]);

    expect(listOne.compare(listTwo)).toEqual('UNEQUAL');
  });

  xtest('order matters to a list', () => {
    const listOne = new List([1, 2, 3]);
    const listTwo = new List([3, 2, 1]);

    expect(listOne.compare(listTwo)).toEqual('UNEQUAL');
  });

  xtest('same digits but different numbers', () => {
    const listOne = new List([1, 0, 1]);
    const listTwo = new List([10, 1]);

    expect(listOne.compare(listTwo)).toEqual('UNEQUAL');
  });

});