|
1 |
| -local is_sublist = require('sublist') |
| 1 | +local sublist = require('sublist') |
2 | 2 |
|
3 | 3 | describe('sublist', function()
|
4 |
| - it('should consider an empty list to be a sublist of an empty list', function() |
5 |
| - assert.equal(true, is_sublist({}, {})) |
| 4 | + it('empty lists', function() |
| 5 | + assert.equal('equal', sublist({}, {})) |
6 | 6 | end)
|
7 | 7 |
|
8 |
| - it('should consider an empty list to be a sublist of a non-empty list', function() |
9 |
| - assert.equal(true, is_sublist({}, { 1, 2, 3 })) |
| 8 | + it('empty list within non empty list', function() |
| 9 | + assert.equal('sublist', sublist({}, { 1, 2, 3 })) |
10 | 10 | end)
|
11 | 11 |
|
12 |
| - it('should consider a list to be a sublist of itself', function() |
13 |
| - assert.equal(true, is_sublist({ 1, 2, 3 }, { 1, 2, 3 })) |
| 12 | + it('non empty list contains empty list', function() |
| 13 | + assert.equal('superlist', sublist({ 1, 2, 3 }, {})) |
14 | 14 | end)
|
15 | 15 |
|
16 |
| - it('should not consider a subset to be a sublist', function() |
17 |
| - assert.equal(false, is_sublist({ 1, 2, 3 }, { 2, 1, 3 })) |
| 16 | + it('list equals itself', function() |
| 17 | + assert.equal('equal', sublist({ 1, 2, 3 }, { 1, 2, 3 })) |
18 | 18 | end)
|
19 | 19 |
|
20 |
| - it('should find a sublist at the beginning of a list', function() |
21 |
| - assert.equal(true, is_sublist({ 11, 22, 33 }, { 11, 22, 33, 44, 55 })) |
| 20 | + it('different lists', function() |
| 21 | + assert.equal('unequal', sublist({ 1, 2, 3 }, { 2, 3, 4 })) |
22 | 22 | end)
|
23 | 23 |
|
24 |
| - it('should find a sublist in the middle of a list', function() |
25 |
| - assert.equal(true, is_sublist({ 12, 13, 14 }, { 11, 12, 13, 14, 15 })) |
| 24 | + it('false start', function() |
| 25 | + assert.equal('sublist', sublist({ 1, 2, 5 }, { 0, 1, 2, 3, 1, 2, 5, 6 })) |
26 | 26 | end)
|
27 | 27 |
|
28 |
| - it('should find a sublist at the end of a list', function() |
29 |
| - assert.equal(true, is_sublist({ 30, 40, 50 }, { 10, 20, 30, 40, 50 })) |
| 28 | + it('consecutive', function() |
| 29 | + assert.equal('sublist', sublist({ 1, 1, 2 }, { 0, 1, 1, 1, 2, 1, 2 })) |
30 | 30 | end)
|
31 | 31 |
|
32 |
| - it('should be able to determine when a list is not a sublist', function() |
33 |
| - assert.equal(false, is_sublist({ 1, 2, 3 }, { 5, 6, 7, 8, 9 })) |
| 32 | + it('sublist at start', function() |
| 33 | + assert.equal('sublist', sublist({ 0, 1, 2 }, { 0, 1, 2, 3, 4, 5 })) |
34 | 34 | end)
|
35 | 35 |
|
36 |
| - it('should not consider almost sublists to be sublists', function() |
37 |
| - assert.equal(false, is_sublist({ 3, 4, 5 }, { 1, 2, 4, 5, 6 })) |
38 |
| - assert.equal(false, is_sublist({ 3, 4, 5 }, { 1, 2, 3, 4, 6 })) |
| 36 | + it('sublist in middle', function() |
| 37 | + assert.equal('sublist', sublist({ 2, 3, 4 }, { 0, 1, 2, 3, 4, 5 })) |
39 | 38 | end)
|
40 | 39 |
|
41 |
| - it('should find a sublist when there are multiple instances of the sublist', function() |
42 |
| - assert.equal(true, is_sublist({ 1, 2, 3 }, { 0, 1, 2, 3, 4, 1, 2, 3, 6 })) |
| 40 | + it('sublist at end', function() |
| 41 | + assert.equal('sublist', sublist({ 3, 4, 5 }, { 0, 1, 2, 3, 4, 5 })) |
| 42 | + end) |
| 43 | + |
| 44 | + it('at start of superlist', function() |
| 45 | + assert.equal('superlist', sublist({ 0, 1, 2, 3, 4, 5 }, { 0, 1, 2 })) |
| 46 | + end) |
| 47 | + |
| 48 | + it('in middle of superlist', function() |
| 49 | + assert.equal('superlist', sublist({ 0, 1, 2, 3, 4, 5 }, { 2, 3 })) |
| 50 | + end) |
| 51 | + |
| 52 | + it('at end of superlist', function() |
| 53 | + assert.equal('superlist', sublist({ 0, 1, 2, 3, 4, 5 }, { 3, 4, 5 })) |
| 54 | + end) |
| 55 | + |
| 56 | + it('first list missing element from second list', function() |
| 57 | + assert.equal('unequal', sublist({ 1, 3 }, { 1, 2, 3 })) |
| 58 | + end) |
| 59 | + |
| 60 | + it('second list missing element from first list', function() |
| 61 | + assert.equal('unequal', sublist({ 1, 2, 3 }, { 1, 3 })) |
| 62 | + end) |
| 63 | + |
| 64 | + it('first list missing additional digits from second list', function() |
| 65 | + assert.equal('unequal', sublist({ 1, 2 }, { 1, 22 })) |
| 66 | + end) |
| 67 | + |
| 68 | + it('order matters to a list', function() |
| 69 | + assert.equal('unequal', sublist({ 1, 2, 3 }, { 3, 2, 1 })) |
| 70 | + end) |
| 71 | + |
| 72 | + it('same digits but different numbers', function() |
| 73 | + assert.equal('unequal', sublist({ 1, 0, 1 }, { 10, 1 })) |
43 | 74 | end)
|
44 | 75 | end)
|
0 commit comments