|
1 | 1 | local rectangles = require('rectangles')
|
2 | 2 |
|
3 |
| --- LuaFormatter off |
4 | 3 | describe('rectangles', function()
|
5 |
| - it('should find 0 rectangles in an empty grid', function() |
| 4 | + it('no rows', function() |
6 | 5 | assert.equal(0, rectangles.count({}))
|
7 | 6 | end)
|
8 | 7 |
|
9 |
| - it('should find 0 rectangles in a non-empty grid', function() |
| 8 | + it('no columns', function() |
10 | 9 | assert.equal(0, rectangles.count({
|
11 |
| - ' ', |
12 |
| - ' ' |
| 10 | + '' -- |
13 | 11 | }))
|
14 | 12 | end)
|
15 | 13 |
|
16 |
| - it('should find a single rectangle', function() |
| 14 | + it('no rectangles', function() |
| 15 | + assert.equal(0, rectangles.count({ |
| 16 | + ' ' -- |
| 17 | + })) |
| 18 | + end) |
| 19 | + |
| 20 | + it('one rectangle', function() |
17 | 21 | assert.equal(1, rectangles.count({
|
18 |
| - '+-+', |
19 |
| - '| |', |
20 |
| - '+-+' |
| 22 | + '+-+', -- , |
| 23 | + '| |', -- , |
| 24 | + '+-+' -- |
21 | 25 | }))
|
22 | 26 | end)
|
23 | 27 |
|
24 |
| - it('should find connected rectangles', function() |
| 28 | + it('two rectangles without shared parts', function() |
25 | 29 | assert.equal(2, rectangles.count({
|
26 |
| - ' +-+', |
27 |
| - ' | |', |
28 |
| - '+-+-+', |
29 |
| - '| | ', |
30 |
| - '+-+ ' |
| 30 | + ' +-+', -- , |
| 31 | + ' | |', -- , |
| 32 | + '+-+-+', -- , |
| 33 | + '| | ', -- , |
| 34 | + '+-+ ' -- |
31 | 35 | }))
|
32 | 36 | end)
|
33 | 37 |
|
34 |
| - it('should find nested rectangles', function() |
| 38 | + it('five rectangles with shared parts', function() |
35 | 39 | assert.equal(5, rectangles.count({
|
36 |
| - ' +-+', |
37 |
| - ' | |', |
38 |
| - '+-+-+', |
39 |
| - '| | |', |
40 |
| - '+-+-+' |
| 40 | + ' +-+', -- , |
| 41 | + ' | |', -- , |
| 42 | + '+-+-+', -- , |
| 43 | + '| | |', -- , |
| 44 | + '+-+-+' -- |
| 45 | + })) |
| 46 | + end) |
| 47 | + |
| 48 | + it('rectangle of height 1 is counted', function() |
| 49 | + assert.equal(1, rectangles.count({ |
| 50 | + '+--+', -- , |
| 51 | + '+--+' -- |
41 | 52 | }))
|
42 | 53 | end)
|
43 | 54 |
|
44 |
| - it('should not count incomplete rectangles', function() |
| 55 | + it('rectangle of width 1 is counted', function() |
45 | 56 | assert.equal(1, rectangles.count({
|
46 |
| - ' +-+', |
47 |
| - ' |', |
48 |
| - '+-+-+', |
49 |
| - '| | -', |
50 |
| - '+-+-+' |
| 57 | + '++', -- , |
| 58 | + '||', -- , |
| 59 | + '++' -- |
| 60 | + })) |
| 61 | + end) |
| 62 | + |
| 63 | + it('1x1 square is counted', function() |
| 64 | + assert.equal(1, rectangles.count({ |
| 65 | + '++', -- , |
| 66 | + '++' -- |
| 67 | + })) |
| 68 | + end) |
| 69 | + |
| 70 | + it('only complete rectangles are counted', function() |
| 71 | + assert.equal(1, rectangles.count({ |
| 72 | + ' +-+', -- , |
| 73 | + ' |', -- , |
| 74 | + '+-+-+', -- , |
| 75 | + '| | -', -- , |
| 76 | + '+-+-+' -- |
| 77 | + })) |
| 78 | + end) |
| 79 | + |
| 80 | + it('rectangles can be of different sizes', function() |
| 81 | + assert.equal(3, rectangles.count({ |
| 82 | + '+------+----+', -- , |
| 83 | + '| | |', -- , |
| 84 | + '+---+--+ |', -- , |
| 85 | + '| | |', -- , |
| 86 | + '+---+-------+' -- |
51 | 87 | }))
|
52 | 88 | end)
|
53 | 89 |
|
54 |
| - it('should not count rectangles without 4 corners', function() |
| 90 | + it('corner is required for a rectangle to be complete', function() |
55 | 91 | assert.equal(2, rectangles.count({
|
56 |
| - '+------+----+', |
57 |
| - '| | |', |
58 |
| - '+------+ |', |
59 |
| - '| | |', |
60 |
| - '+---+-------+' |
| 92 | + '+------+----+', -- , |
| 93 | + '| | |', -- , |
| 94 | + '+------+ |', -- , |
| 95 | + '| | |', -- , |
| 96 | + '+---+-------+' -- |
61 | 97 | }))
|
62 | 98 | end)
|
63 | 99 |
|
64 |
| - it('should find rectangles in large input', function() |
| 100 | + it('large input with many rectangles', function() |
65 | 101 | assert.equal(60, rectangles.count({
|
66 |
| - ' ', |
67 |
| - ' +---+--+----+ ', |
68 |
| - ' | +--+----+ ', |
69 |
| - ' +---+--+ | ', |
70 |
| - ' | +--+----+ ', |
71 |
| - ' +---+--+--+-+ ', |
72 |
| - ' +---+--+--+-+ ', |
73 |
| - ' +------+ | | ', |
74 |
| - ' +-+ ', |
75 |
| - ' ' |
| 102 | + '+---+--+----+', -- , |
| 103 | + '| +--+----+', -- , |
| 104 | + '+---+--+ |', -- , |
| 105 | + '| +--+----+', -- , |
| 106 | + '+---+--+--+-+', -- , |
| 107 | + '+---+--+--+-+', -- , |
| 108 | + '+------+ | |', -- , |
| 109 | + ' +-+' -- |
76 | 110 | }))
|
77 | 111 | end)
|
78 | 112 | end)
|
79 |
| --- LuaFormatter on |
|
0 commit comments