Use shared tests repository instead of src/tests
This commit is contained in:
parent
86b097171e
commit
0663d7fa10
39 changed files with 3 additions and 276 deletions
4
.gitmodules
vendored
4
.gitmodules
vendored
|
@ -1,3 +1,3 @@
|
|||
[submodule "src/tests_shared"]
|
||||
path = src/tests_shared
|
||||
[submodule "src/tests"]
|
||||
path = src/tests
|
||||
url = git@github.com:tobast/mpri18-funcprog-tests.git
|
||||
|
|
1
src/tests
Submodule
1
src/tests
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 99e02259731e34422067235879d9f4698490466b
|
4
src/tests/.gitignore
vendored
4
src/tests/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
|||
*.err
|
||||
*.out
|
||||
*.exe
|
||||
*.c
|
|
@ -1,20 +0,0 @@
|
|||
1
|
||||
0
|
||||
1
|
||||
0
|
||||
0
|
||||
24
|
||||
120
|
||||
8
|
||||
13
|
||||
5
|
||||
0
|
||||
1
|
||||
7
|
||||
1
|
||||
1
|
||||
2
|
||||
6
|
||||
24
|
||||
120
|
||||
42
|
|
@ -1,88 +0,0 @@
|
|||
(* Thunks. *)
|
||||
let force = fun x -> x 0 in
|
||||
(* Church Booleans. *)
|
||||
let false = fun x -> fun y -> y in
|
||||
let true = fun x -> fun y -> x in
|
||||
let k = true in
|
||||
let cond = fun p -> fun x -> fun y -> p x y in
|
||||
let forcecond = fun p -> fun x -> fun y -> force (p x y) in
|
||||
let bool2int = fun b -> cond b 1 0 in
|
||||
let _ = print (bool2int true) in
|
||||
let _ = print (bool2int false) in
|
||||
(* Church pairs. *)
|
||||
let pair = fun x -> fun y -> fun p -> cond p x y in
|
||||
let fst = fun p -> p true in
|
||||
let snd = fun p -> p false in
|
||||
(* Church naturals. *)
|
||||
let zero = fun f -> fun x -> x in
|
||||
let one = fun f -> fun x -> f x in
|
||||
let plus = fun m -> fun n -> fun f -> fun x -> m f (n f x) in
|
||||
let two = plus one one in
|
||||
let three = plus one two in
|
||||
let four = plus two two in
|
||||
let five = plus four one in
|
||||
let six = plus four two in
|
||||
let succ = plus one in
|
||||
let mult = fun m -> fun n -> fun f -> m (n f) in
|
||||
let exp = fun m -> fun n -> n m in
|
||||
let is_zero = fun n -> n (k false) true in
|
||||
let convert = fun n -> n (fun x -> x + 1) 0 in
|
||||
let _ = print (bool2int (is_zero zero)) in
|
||||
let _ = print (bool2int (is_zero one)) in
|
||||
let _ = print (bool2int (is_zero two)) in
|
||||
(* Factorial, based on Church naturals. *)
|
||||
let loop = fun p ->
|
||||
let n = succ (fst p) in
|
||||
pair n (mult n (snd p))
|
||||
in
|
||||
let fact = fun n ->
|
||||
snd (n loop (pair zero one))
|
||||
in
|
||||
let _ = print (convert (fact four)) in
|
||||
let _ = print (convert (fact five)) in
|
||||
(* Fibonacci, based on Church naturals. *)
|
||||
let loop = fun p ->
|
||||
let fib1 = fst p in
|
||||
pair (plus fib1 (snd p)) fib1
|
||||
in
|
||||
let fib = fun n ->
|
||||
snd (n loop (pair one one))
|
||||
in
|
||||
let _ = print (convert (fib five)) in
|
||||
let _ = print (convert (fib six)) in
|
||||
(* Predecessor. *)
|
||||
let loop = fun p ->
|
||||
let pred = fst p in
|
||||
pair (succ pred) pred
|
||||
in
|
||||
let pred = fun n ->
|
||||
snd (n loop (pair zero zero))
|
||||
in
|
||||
let _ = print (convert (pred six)) in
|
||||
(* Comparison, yielding a Church Boolean. *)
|
||||
let geq = fun m -> fun n ->
|
||||
m pred n (k false) true
|
||||
in
|
||||
let _ = print (bool2int (geq four six)) in
|
||||
let _ = print (bool2int (geq six one)) in
|
||||
(* Iteration. *)
|
||||
let iter = fun f -> fun n ->
|
||||
n f (f one)
|
||||
in
|
||||
(* Ackermann's function. *)
|
||||
let ack = fun n -> n iter succ n in
|
||||
let _ = print (convert (ack two)) in
|
||||
(* A fixpoint. *)
|
||||
let fix = fun f -> (fun y -> f (fun z -> y y z)) (fun y -> f (fun z -> y y z)) in
|
||||
(* Another version of fact. *)
|
||||
let fact = fun n ->
|
||||
fix (fun fact -> fun n -> forcecond (is_zero n) (fun _ -> one) (fun _ -> mult n (fact (pred n)))) n
|
||||
in
|
||||
let _ = print (convert (fact zero)) in
|
||||
let _ = print (convert (fact one)) in
|
||||
let _ = print (convert (fact two)) in
|
||||
let _ = print (convert (fact three)) in
|
||||
let _ = print (convert (fact four)) in
|
||||
let _ = print (convert (fact five)) in
|
||||
|
||||
print 42
|
|
@ -1 +0,0 @@
|
|||
42
|
|
@ -1,16 +0,0 @@
|
|||
let i = fun x -> x in
|
||||
let k = fun x -> fun y -> x in
|
||||
let zero = fun f -> i in
|
||||
let one = fun f -> fun x -> f x in
|
||||
let plus = fun m -> fun n -> fun f -> fun x -> m f (n f x) in
|
||||
let succ = plus one in
|
||||
let mult = fun m -> fun n -> fun f -> m (n f) in
|
||||
let exp = fun m -> fun n -> n m in
|
||||
let two = succ one in
|
||||
let three = succ two in
|
||||
let six = mult two three in
|
||||
let seven = succ six in
|
||||
let twenty_one = mult three seven in
|
||||
let forty_two = mult two twenty_one in
|
||||
let convert = fun n -> n (fun x -> x + 1) 0 in
|
||||
print (convert forty_two)
|
|
@ -1 +0,0 @@
|
|||
42
|
|
@ -1 +0,0 @@
|
|||
print (21 + 21)
|
|
@ -1 +0,0 @@
|
|||
../tests_shared/if_fib.exp
|
|
@ -1 +0,0 @@
|
|||
../tests_shared/if_fib.lambda
|
|
@ -1,2 +0,0 @@
|
|||
1
|
||||
1
|
|
@ -1,26 +0,0 @@
|
|||
let i = fun x -> x in
|
||||
let k = fun x -> fun y -> x in
|
||||
let zero = fun f -> i in
|
||||
let one = fun f -> fun x -> f x in
|
||||
let plus = fun m -> fun n -> fun f -> fun x -> m f (n f x) in
|
||||
let succ = plus one in
|
||||
let mult = fun m -> fun n -> fun f -> m (n f) in
|
||||
let exp = fun m -> fun n -> n m in
|
||||
let two = succ one in
|
||||
let three = succ two in
|
||||
let six = mult two three in
|
||||
let seven = succ six in
|
||||
let twenty_one = mult three seven in
|
||||
let forty_two = mult two twenty_one in
|
||||
let convert = fun n -> n (fun x -> x + 1) 0 in
|
||||
|
||||
let nothing =
|
||||
ifzero convert forty_two then
|
||||
print 0
|
||||
else
|
||||
print 1
|
||||
in
|
||||
ifzero convert zero then
|
||||
print 1
|
||||
else
|
||||
print 0
|
|
@ -1,2 +0,0 @@
|
|||
1
|
||||
1
|
|
@ -1,8 +0,0 @@
|
|||
let succeed = fun x -> print 1 in
|
||||
let fail = fun x -> print 0 in
|
||||
|
||||
let true = fun x -> 0 in
|
||||
let false = fun x -> 1 in
|
||||
|
||||
let nothing = ifzero true 0 then succeed 0 else fail 0 in
|
||||
ifzero false 0 then fail 0 else succeed 0
|
|
@ -1 +0,0 @@
|
|||
../tests_shared/if_nested.exp
|
|
@ -1 +0,0 @@
|
|||
../tests_shared/if_nested.lambda
|
|
@ -1,10 +0,0 @@
|
|||
(* This program is supposed to never terminate.
|
||||
This can actually work if the C compiler is
|
||||
smart enough to recognize and optimize tail
|
||||
calls. It works for me with clang but not with
|
||||
gcc, for some reason. *)
|
||||
let rec loop = fun x ->
|
||||
let _ = print x in
|
||||
loop (x + 1)
|
||||
in
|
||||
loop 0
|
|
@ -1 +0,0 @@
|
|||
42
|
|
@ -1,2 +0,0 @@
|
|||
let sum = fun x -> fun y -> x + y in
|
||||
print(sum 40 2)
|
|
@ -1,10 +0,0 @@
|
|||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
|
@ -1,8 +0,0 @@
|
|||
let rec print_n = fun cur -> fun n ->
|
||||
ifzero n - cur then
|
||||
0
|
||||
else
|
||||
let x = print 0 in
|
||||
print_n (cur + 1) n
|
||||
in
|
||||
print_n 0 10
|
|
@ -1,2 +0,0 @@
|
|||
42
|
||||
42
|
|
@ -1,5 +0,0 @@
|
|||
let sum = fun x -> fun y -> fun z -> x + y + z in
|
||||
let plus2 = sum 1 1 in
|
||||
|
||||
let _ = print (sum 30 10 2) in
|
||||
print (plus2 40)
|
|
@ -1,2 +0,0 @@
|
|||
42
|
||||
42
|
|
@ -1,2 +0,0 @@
|
|||
(* Because [print] returns its argument, this program should print 42 twice. *)
|
||||
print (print 42)
|
|
@ -1 +0,0 @@
|
|||
5040
|
|
@ -1,9 +0,0 @@
|
|||
let rec fact = fun n ->
|
||||
ifzero n then
|
||||
1
|
||||
else
|
||||
let sub_val = fact (n - 1) in
|
||||
n * sub_val
|
||||
in
|
||||
|
||||
print (fact 7)
|
|
@ -1,9 +0,0 @@
|
|||
1
|
||||
1
|
||||
2
|
||||
3
|
||||
5
|
||||
8
|
||||
13
|
||||
21
|
||||
34
|
|
@ -1,25 +0,0 @@
|
|||
let fibo = fun n ->
|
||||
let rec fibo_inner = fun i -> fun last -> fun last_last ->
|
||||
ifzero (n - i) then
|
||||
last + last_last
|
||||
else
|
||||
fibo_inner (i+1) (last + last_last) last
|
||||
in
|
||||
|
||||
ifzero n then
|
||||
1
|
||||
else ifzero (n - 1) then
|
||||
1
|
||||
else
|
||||
fibo_inner 2 1 1
|
||||
in
|
||||
|
||||
let x = print (fibo 0) in
|
||||
let x = print (fibo 1) in
|
||||
let x = print (fibo 2) in
|
||||
let x = print (fibo 3) in
|
||||
let x = print (fibo 4) in
|
||||
let x = print (fibo 5) in
|
||||
let x = print (fibo 6) in
|
||||
let x = print (fibo 7) in
|
||||
print (fibo 8)
|
|
@ -1 +0,0 @@
|
|||
42
|
|
@ -1,6 +0,0 @@
|
|||
let increase = fun x -> x + 1 in
|
||||
let increase = fun x ->
|
||||
let lop = (increase x) in
|
||||
lop + 1 in
|
||||
|
||||
print (increase 40)
|
|
@ -1 +0,0 @@
|
|||
../tests_shared/ren.exp
|
|
@ -1 +0,0 @@
|
|||
../tests_shared/ren.lambda
|
|
@ -1 +0,0 @@
|
|||
42
|
|
@ -1,2 +0,0 @@
|
|||
let id = fun x -> x in
|
||||
print (id 42)
|
|
@ -1 +0,0 @@
|
|||
1
|
|
@ -1 +0,0 @@
|
|||
ifzero 42 then print 0 else print 1
|
|
@ -1 +0,0 @@
|
|||
Subproject commit ab7549347e5b6b51183c5704048c6768aab23d86
|
Loading…
Reference in a new issue