|
76 | 76 | -> { c.clamp(one...two) }.should raise_error(ArgumentError) |
77 | 77 | end |
78 | 78 |
|
| 79 | + context 'with nil as the max argument' do |
| 80 | + it 'returns min argument if less than it' do |
| 81 | + one = ComparableSpecs::WithOnlyCompareDefined.new(1) |
| 82 | + zero = ComparableSpecs::WithOnlyCompareDefined.new(0) |
| 83 | + c = ComparableSpecs::Weird.new(0) |
| 84 | + |
| 85 | + c.clamp(one, nil).should equal(one) |
| 86 | + c.clamp(zero, nil).should equal(c) |
| 87 | + end |
| 88 | + |
| 89 | + it 'always returns self if greater than min argument' do |
| 90 | + one = ComparableSpecs::WithOnlyCompareDefined.new(1) |
| 91 | + two = ComparableSpecs::WithOnlyCompareDefined.new(2) |
| 92 | + c = ComparableSpecs::Weird.new(2) |
| 93 | + |
| 94 | + c.clamp(one, nil).should equal(c) |
| 95 | + c.clamp(two, nil).should equal(c) |
| 96 | + end |
| 97 | + end |
| 98 | + |
79 | 99 | context 'with endless range' do |
80 | 100 | it 'returns minimum value of the range parameters if less than it' do |
81 | 101 | one = ComparableSpecs::WithOnlyCompareDefined.new(1) |
|
103 | 123 | end |
104 | 124 | end |
105 | 125 |
|
| 126 | + context 'with nil as the min argument' do |
| 127 | + it 'returns max argument if greater than it' do |
| 128 | + one = ComparableSpecs::WithOnlyCompareDefined.new(1) |
| 129 | + c = ComparableSpecs::Weird.new(2) |
| 130 | + |
| 131 | + c.clamp(nil, one).should equal(one) |
| 132 | + end |
| 133 | + |
| 134 | + it 'always returns self if less than max argument' do |
| 135 | + one = ComparableSpecs::WithOnlyCompareDefined.new(1) |
| 136 | + zero = ComparableSpecs::WithOnlyCompareDefined.new(0) |
| 137 | + c = ComparableSpecs::Weird.new(0) |
| 138 | + |
| 139 | + c.clamp(nil, one).should equal(c) |
| 140 | + c.clamp(nil, zero).should equal(c) |
| 141 | + end |
| 142 | + end |
| 143 | + |
106 | 144 | context 'with beginless range' do |
107 | 145 | it 'returns maximum value of the range parameters if greater than it' do |
108 | 146 | one = ComparableSpecs::WithOnlyCompareDefined.new(1) |
|
128 | 166 | end |
129 | 167 | end |
130 | 168 |
|
| 169 | + context 'with nil as the min and the max argument' do |
| 170 | + it 'always returns self' do |
| 171 | + c = ComparableSpecs::Weird.new(1) |
| 172 | + |
| 173 | + c.clamp(nil, nil).should equal(c) |
| 174 | + end |
| 175 | + end |
| 176 | + |
131 | 177 | context 'with beginless-and-endless range' do |
132 | 178 | it 'always returns self' do |
133 | 179 | c = ComparableSpecs::Weird.new(1) |
|
0 commit comments