mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
Исправлен итератор в std::range для реверсивных промежутков. Fix #3
This commit is contained in:
parent
7711170601
commit
00db00c2aa
@ -134,7 +134,7 @@ public final class std_range implements Function {
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return value < toInt;
|
||||
return (stepInt > 0) ? (value < toInt) : (value > toInt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -154,7 +154,7 @@ public final class std_range implements Function {
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return value < to;
|
||||
return (step > 0) ? (value < to) : (value > to);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,6 +28,18 @@ def testRangeParamsReversed() {
|
||||
assertEquals(5, x[5])
|
||||
}
|
||||
|
||||
def testRangeIterator() {
|
||||
x = range(0, 9, 2)
|
||||
arr = reduce(x, [], def(acc, e) = acc += e)
|
||||
assertEquals([0, 2, 4, 6, 8], arr)
|
||||
}
|
||||
|
||||
def testRangeReversedIterator() {
|
||||
x = range(20, 9, -2)
|
||||
arr = reduce(x, [], def(acc, e) = acc += e)
|
||||
assertEquals([20, 18, 16, 14, 12, 10], arr)
|
||||
}
|
||||
|
||||
def testRangeLength() {
|
||||
assertEquals(10, length(range(0, 10, 1)))
|
||||
assertEquals(5, length(range(0, 10, 2)))
|
||||
|
Loading…
Reference in New Issue
Block a user