diff --git a/test/Core/Eval/Positive.hs b/test/Core/Eval/Positive.hs index 8d6f1aad21..f689b65ea1 100644 --- a/test/Core/Eval/Positive.hs +++ b/test/Core/Eval/Positive.hs @@ -229,5 +229,10 @@ tests = "LetRec" "." "test040.jvc" - "out/test040.out" + "out/test040.out", + PosTest + "Match with complex patterns" + "." + "test041.jvc" + "out/test041.out" ] diff --git a/tests/Core/positive/out/test041.out b/tests/Core/positive/out/test041.out new file mode 100644 index 0000000000..2f5bb2d1ca --- /dev/null +++ b/tests/Core/positive/out/test041.out @@ -0,0 +1,7 @@ +cons 9 (cons 7 (cons 5 (cons 3 (cons 1 nil)))) +-12096 +-1448007509520 +5510602057585725 +-85667472308246220 +527851146861989286336 +-441596546382859135501706333021475 diff --git a/tests/Core/positive/test041.jvc b/tests/Core/positive/test041.jvc new file mode 100644 index 0000000000..a572db1d24 --- /dev/null +++ b/tests/Core/positive/test041.jvc @@ -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))