mirror of
https://github.com/edwinb/Idris2-boot.git
synced 2024-12-25 05:43:19 +03:00
Add first batch of totality checking tests
This commit is contained in:
parent
b1acceb870
commit
fb7190b337
@ -32,7 +32,8 @@ idrisTests
|
||||
"interface005",
|
||||
"import001", "import002",
|
||||
"lazy001",
|
||||
"record001", "record002"]
|
||||
"record001", "record002",
|
||||
"total001", "total002", "total003"]
|
||||
|
||||
chdir : String -> IO Bool
|
||||
chdir dir
|
||||
|
17
tests/idris2/total001/Total.idr
Normal file
17
tests/idris2/total001/Total.idr
Normal file
@ -0,0 +1,17 @@
|
||||
data Vect : Nat -> Type -> Type where
|
||||
Nil : Vect Z a
|
||||
(::) : a -> Vect k a -> Vect (S k) a
|
||||
|
||||
data Fin : Nat -> Type where
|
||||
FZ : Fin (S k)
|
||||
FS : Fin k -> Fin (S k)
|
||||
|
||||
lookup : Fin n -> Vect n a -> a
|
||||
lookup FZ (x :: xs) = x
|
||||
lookup (FS k) (x :: xs) = lookup k xs
|
||||
|
||||
lookup' : Fin n -> Vect n a -> a
|
||||
lookup' (FS k) (x :: xs) = lookup' k xs
|
||||
|
||||
lookup'' : Fin n -> Vect n a -> a
|
||||
lookup'' n xs = lookup' n xs
|
7
tests/idris2/total001/expected
Normal file
7
tests/idris2/total001/expected
Normal file
@ -0,0 +1,7 @@
|
||||
1/1: Building Total (Total.idr)
|
||||
Welcome to Idris 2 version 0.0. Enjoy yourself!
|
||||
Main> Main.lookup: All cases covered
|
||||
Main> Main.lookup':
|
||||
lookup' FZ _
|
||||
Main> Main.lookup'': Calls non covering function Main.lookup'
|
||||
Main> Bye for now!
|
4
tests/idris2/total001/input
Normal file
4
tests/idris2/total001/input
Normal file
@ -0,0 +1,4 @@
|
||||
:missing lookup
|
||||
:missing lookup'
|
||||
:missing lookup''
|
||||
:q
|
3
tests/idris2/total001/run
Executable file
3
tests/idris2/total001/run
Executable file
@ -0,0 +1,3 @@
|
||||
$1 Total.idr < input
|
||||
|
||||
rm -rf build
|
13
tests/idris2/total002/Total.idr
Normal file
13
tests/idris2/total002/Total.idr
Normal file
@ -0,0 +1,13 @@
|
||||
data Fin : Nat -> Type where
|
||||
FZ : Fin (S k)
|
||||
FS : Fin k -> Fin (S k)
|
||||
|
||||
noFinZ : Fin Z -> Void
|
||||
noFinZ FZ impossible
|
||||
noFinZ (FS k) impossible
|
||||
|
||||
noFinZ' : Fin Z -> Void
|
||||
noFinZ' x impossible
|
||||
|
||||
noEmpty : Void -> Fin Z
|
||||
noEmpty t impossible
|
6
tests/idris2/total002/expected
Normal file
6
tests/idris2/total002/expected
Normal file
@ -0,0 +1,6 @@
|
||||
1/1: Building Total (Total.idr)
|
||||
Welcome to Idris 2 version 0.0. Enjoy yourself!
|
||||
Main> Main.noFinZ: All cases covered
|
||||
Main> Main.noFinZ': All cases covered
|
||||
Main> Main.noEmpty: All cases covered
|
||||
Main> Bye for now!
|
4
tests/idris2/total002/input
Normal file
4
tests/idris2/total002/input
Normal file
@ -0,0 +1,4 @@
|
||||
:missing noFinZ
|
||||
:missing noFinZ'
|
||||
:missing noEmpty
|
||||
:q
|
3
tests/idris2/total002/run
Executable file
3
tests/idris2/total002/run
Executable file
@ -0,0 +1,3 @@
|
||||
$1 Total.idr < input
|
||||
|
||||
rm -rf build
|
25
tests/idris2/total003/Total.idr
Normal file
25
tests/idris2/total003/Total.idr
Normal file
@ -0,0 +1,25 @@
|
||||
onlyOne : Int -> Int
|
||||
onlyOne 1 = 2
|
||||
|
||||
covered : Int -> Int
|
||||
covered 1 = 2
|
||||
covered 2 = 3
|
||||
covered _ = 94
|
||||
|
||||
data IntNat : Integer -> Nat -> Type where
|
||||
IsZero : IntNat 0 Z
|
||||
IsSuc : IntNat 1 (S k)
|
||||
|
||||
-- Only identified as covering if 'x' has multiplicity 0 because then it
|
||||
-- doesn't show up in the case tree!
|
||||
matchInt : (0 x : Integer) -> (n : Nat) -> IntNat x n -> String
|
||||
matchInt 0 Z IsZero = "Zero"
|
||||
matchInt 1 (S k) IsSuc = "Non Zero"
|
||||
|
||||
-- Should be identified as covering but isn't yet since the checker requires
|
||||
-- a catch all case. This does at least test that the declared 'impossible'
|
||||
-- case really is impossible; we can update it when the checker improves!
|
||||
matchInt' : (x : Integer) -> (n : Nat) -> IntNat x n -> String
|
||||
matchInt' 0 Z IsZero = "Zero"
|
||||
matchInt' 1 (S k) IsSuc = "Non Zero"
|
||||
matchInt' 0 (S k) x impossible
|
10
tests/idris2/total003/expected
Normal file
10
tests/idris2/total003/expected
Normal file
@ -0,0 +1,10 @@
|
||||
1/1: Building Total (Total.idr)
|
||||
Welcome to Idris 2 version 0.0. Enjoy yourself!
|
||||
Main> Main.onlyOne:
|
||||
onlyOne _
|
||||
Main> Main.covered: All cases covered
|
||||
Main> Main.matchInt: All cases covered
|
||||
Main> Main.matchInt':
|
||||
matchInt' _ _ IsZero
|
||||
matchInt' _ _ IsSuc
|
||||
Main> Bye for now!
|
5
tests/idris2/total003/input
Normal file
5
tests/idris2/total003/input
Normal file
@ -0,0 +1,5 @@
|
||||
:missing onlyOne
|
||||
:missing covered
|
||||
:missing matchInt
|
||||
:missing matchInt'
|
||||
:q
|
3
tests/idris2/total003/run
Executable file
3
tests/idris2/total003/run
Executable file
@ -0,0 +1,3 @@
|
||||
$1 Total.idr < input
|
||||
|
||||
rm -rf build
|
Loading…
Reference in New Issue
Block a user