Skip to content

Commit 4920601

Browse files
authored
Add tests for Nat ranges and fix bad range [1,2..1] behaviour. (#1794)
Co-authored-by: Marcin Pastudzki <[email protected]>
1 parent 84b0643 commit 4920601

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

libs/prelude/Prelude/Types.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ Range Nat where
820820
EQ => pure x
821821
GT => assert_total $ takeUntil (<= y) (countFrom x (\n => minus n 1))
822822
rangeFromThenTo x y z = case compare x y of
823-
LT => if z > x
823+
LT => if z >= x
824824
then assert_total $ takeBefore (> z) (countFrom x (plus (minus y x)))
825825
else Nil
826826
EQ => if x == z then pure x else Nil

tests/prelude/nat001/expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1/1: Building nats (nats.idr)

tests/prelude/nat001/nats.idr

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
nats : List Nat -> List Nat
2+
nats = the (List Nat)
3+
4+
singletonRange : nats [1..1] = nats [1]
5+
singletonRange = Refl
6+
7+
basicIncreasingRange : nats [1..3] = nats [1, 2 , 3]
8+
basicIncreasingRange = Refl
9+
10+
basicDecreasingRange : nats [3..1] = nats [3, 2, 1]
11+
basicDecreasingRange = Refl
12+
13+
14+
increasingRangeWithStep : nats [3, 5..11] = nats [3, 5, 7, 9, 11]
15+
increasingRangeWithStep = Refl
16+
17+
increaingRangeWithStepEmpty : nats [3, 5..1] = nats []
18+
increaingRangeWithStepEmpty = Refl
19+
20+
singletonRangeWithStep : nats [3, 4..3] = nats [3]
21+
singletonRangeWithStep = Refl
22+
23+
zeroStepEmptyList : nats [3, 3..5] = nats []
24+
zeroStepEmptyList = Refl
25+
26+
zeroStepWhenBoundEqual : nats [1, 1..1] = nats [1]
27+
zeroStepWhenBoundEqual = Refl
28+
29+
decreasingRangeWithStep : nats [11, 8..1] = nats [11, 8, 5, 2]
30+
decreasingRangeWithStep = Refl
31+
32+
decreasingRangeWithStepEmpty : nats [9, 8..10] = nats []
33+
decreasingRangeWithStepEmpty = Refl
34+
35+
decreasingSingletonRangeWithStep : nats [9, 8..9] = nats [9]
36+
decreasingSingletonRangeWithStep = Refl

tests/prelude/nat001/run

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rm -rf build
2+
3+
$1 --check nats.idr

0 commit comments

Comments
 (0)