|
4 | 4 |
|
5 | 5 | method :rangify do |
6 | 6 | test 'Array of consecutive integers should return an array made up of a single range.' do |
7 | | - [1,2,3,4,5].rangify.assert == [1..5] |
| 7 | + [1,2,3,4,5].rangify.assert == ([1..5]) |
8 | 8 | end |
9 | | - |
10 | | - test 'Array of non-consecutive integers should return the original array.' do |
11 | | - [1,3,5,7].rangify.assert == [1,3,5,7] |
| 9 | + |
| 10 | + test 'Array of non-consecutive integers should return single-element ranges.' do |
| 11 | + [1,3,5,7].rangify.assert == ([1..1, 3..3, 5..5, 7..7]) |
12 | 12 | end |
13 | 13 |
|
14 | 14 | test 'Array of ranges should return the correct ranges.' do |
15 | 15 | arr = [40..45, 1..3, 4..10, 20..30, 24..28, 42..50, 1..6, 1..3, 1..1] |
16 | | - arr.rangify.assert == [1..10, 20..30, 40..50] |
| 16 | + arr.rangify.assert == ([1..10, 20..30, 40..50]) |
17 | 17 | end |
18 | | - |
| 18 | + |
19 | 19 | test 'Array of ranges and integers should return the correct ranges.' do |
20 | 20 | arr = [99, 100, 1..3, 101, 4..5, 103, 10..19, 99, 20..20, 31, 32..33, 98, 97] |
21 | | - arr.rangify.assert == [1..5, 10..20, 31..33, 97..101, 103] |
22 | | - end |
| 21 | + arr.rangify.assert == ([1..5, 10..20, 31..33, 97..101, 103..103]) |
| 22 | + end |
23 | 23 |
|
24 | 24 | test 'Array of non-consecutive integers should return the correct ranges.' do |
25 | | - [1,2,3,6,7,8,10,15].rangify.assert == [1..3, 6..8, 10, 15] |
| 25 | + [1,2,3,6,7,8,10,15].rangify.assert == ([1..3, 6..8, 10..10, 15..15]) |
26 | 26 | end |
27 | | - |
| 27 | + |
28 | 28 | test 'Element order should not affect the result.' do |
29 | | - [8, 1, 15, 2, 6, 3, 7, 10].rangify.assert == [1..3, 6..8, 10, 15] |
| 29 | + [8, 1, 15, 2, 6, 3, 7, 10].rangify.assert == ([1..3, 6..8, 10..10, 15..15]) |
30 | 30 | end |
31 | | - |
| 31 | + |
32 | 32 | test 'Duplicate elements should not affect the result.' do |
33 | | - [8, 1, 15, 2, 6, 3, 7, 10, 8, 15, 2, 3, 1, 2].rangify.assert == [1..3, 6..8, 10, 15] |
| 33 | + [8, 1, 15, 2, 6, 3, 7, 10, 8, 15, 2, 3, 1, 2].rangify.assert == ([1..3, 6..8, 10..10, 15..15]) |
34 | 34 | end |
35 | 35 | end |
36 | 36 |
|
|
0 commit comments