Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Sep 13, 2022
1 parent 0dba8d3 commit 7935351
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/Core/Eval/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,10 @@ tests =
"LetRec"
"."
"test040.jvc"
"out/test040.out"
"out/test040.out",
PosTest
"Match with complex patterns"
"."
"test041.jvc"
"out/test041.out"
]
7 changes: 7 additions & 0 deletions tests/Core/positive/out/test041.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cons 9 (cons 7 (cons 5 (cons 3 (cons 1 nil))))
-12096
-1448007509520
5510602057585725
-85667472308246220
527851146861989286336
-441596546382859135501706333021475
49 changes: 49 additions & 0 deletions tests/Core/positive/test041.jvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-- match

constr cons 2;
constr nil 0;

def lgen := \n if n = 0 then nil else cons n (lgen (n - 1));

def sum2 := \x {
match x with {
cons x y@(cons z _) -> cons (x + z) (sum2 y);
_ -> x
}
};

constr leaf 0;
constr node 2;

def gen := \n if n <= 0 then leaf else node (gen (n - 2)) (gen (n - 1));

def g;

def f := \t match t with {
leaf -> 1;
node l r ->
match g l, g r with {
leaf, leaf -> 0 - 6;
node l r, leaf -> (f l + f r) * 2;
node l1 r1, node l2 r2 -> (f l1 + f r1) * (f l2 + f r2);
_, node l r -> (f l + f r) * (0 - 3)
}
};

def g := \t {
match t with {
leaf -> t;
node (node _ _) r -> r;
node l r -> node r l;
}
};

def writeLn := \x write x >> write "\n";

writeLn (sum2 (lgen 5)) >>
writeLn (f (gen 10)) >>
writeLn (f (gen 15)) >>
writeLn (f (gen 16)) >>
writeLn (f (gen 17)) >>
writeLn (f (gen 18)) >>
writeLn (f (gen 20))

0 comments on commit 7935351

Please sign in to comment.