1
exercism fetch javascript 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
var List = require('./sublist');


describe('sublist', function () {
  it('two empty lists are equal', function () {
    var listOne = new List();
    var listTwo = new List();

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

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

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

  xit('non empty list contains empty list', function () {
    var listOne = new List([1, 2, 3]);
    var listTwo = new List();

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

  xit('a non-empty list equals itself', function () {
    var listOne = new List([1, 2, 3]);
    var listTwo = new List([1, 2, 3]);

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

  xit('two different lists are unequal', function () {
    var listOne = new List([1, 2, 3]);
    var listTwo = new List([2, 3, 4]);

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

  xit('false start', function () {
    var listOne = new List([1, 2, 5]);
    var listTwo = new List([0, 1, 2, 3, 1, 2, 5, 6]);

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

  xit('consecutive', function () {
    var listOne = new List([1, 1, 2]);
    var listTwo = new List([0, 1, 1, 1, 2, 1, 2]);

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

  xit('sublist at start', function () {
    var listOne = new List([0, 1, 2]);
    var listTwo = new List([0, 1, 2, 3, 4, 5]);

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

  xit('sublist in middle', function () {
    var listOne = new List([2, 3, 4]);
    var listTwo = new List([0, 1, 2, 3, 4, 5]);

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

  xit('sublist at end', function () {
    var listOne = new List([3, 4, 5]);
    var listTwo = new List([0, 1, 2, 3, 4, 5]);

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

  xit('at start of superlist', function () {
    var listOne = new List([0, 1, 2, 3, 4, 5]);
    var listTwo = new List([0, 1, 2]);

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

  xit('in middle of superlist', function () {
    var listOne = new List([0, 1, 2, 3, 4, 5]);
    var listTwo = new List([2, 3]);

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

  xit('at end of superlist', function () {
    var listOne = new List([0, 1, 2, 3, 4, 5]);
    var listTwo = new List([3, 4, 5]);

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

  xit('first list missing element from second list', function () {
    var listOne = new List([1, 3]);
    var listTwo = new List([1, 2, 3]);

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

  xit('second list missing element from first list', function () {
    var listOne = new List([1, 2, 3]);
    var listTwo = new List([1, 3]);

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

  xit('order matters to a list', function () {
    var listOne = new List([1, 2, 3]);
    var listTwo = new List([3, 2, 1]);

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

  xit('same digits but different numbers', function () {
    var listOne = new List([1, 0, 1]);
    var listTwo = new List([10, 1]);

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