Commit 12458501 authored by Julien Lopez's avatar Julien Lopez
Browse files

Add some tests on records

parent 2c640130
......@@ -39,3 +39,15 @@ type typ = (`Empty, []) | (`Tree, (Latin1, (typ, typ)))
let visit_tree_infix (f : Latin1 -> Latin1)(tree : typ) : Latin1 = match tree with
| (`Tree, (str, (left, right))) -> visit_tree_infix f left @ f str @ visit_tree_infix f right
| (`Empty, []) -> ""
type point3d = { a=Float b=Float c=Float }
type stack3d = (`Novalue, []) | (`Stack, (point3d, stack3d))
let push (s : stack3d)(p : point3d) : stack3d = (`Stack, (p, s))
let pop (s : stack3d) : stack3d = match s with
| (`Stack, (_, rest)) -> rest
| e & (`Novalue, []) -> e
let print_stack (s : stack3d) : Latin1 = match s with
| (`Stack, (el, rest)) -> string_of el @ print_stack rest
| (`Novalue, []) -> ""
......@@ -35,3 +35,13 @@ type typ =
| Tree of string * typ * typ
val visit_tree_infix : (string -> string) -> typ -> string
type point3d = { a : float; b : float; c : float }
type stack3d =
| Novalue of unit
| Stack of point3d * stack3d
val push : stack3d -> point3d -> stack3d
val pop : stack3d -> stack3d
val print_stack : stack3d -> string
......@@ -112,6 +112,30 @@ let tests = "Misc" >:::
(Misc.visit_tree_infix (fun x -> string_of_int(Misc.str_len x)^"~") tree);
);
"stack" >:: ( fun test_ctxt ->
let p1 = { Misc.a=(float_of_string "1.2"); Misc.b=(float_of_string "0.3");
Misc.c=(float_of_string "0.5") } in
let p2 = { Misc.a=(float_of_string "-0.2"); Misc.b=(float_of_string "0.4");
Misc.c=(float_of_string "0.7") } in
let stack = Misc.Novalue() in
let stack = Misc.push stack p1 in
assert_equal ~msg:"Test Misc.stack.push1 failed"
"{ a=1.200000 b=0.300000 c=0.500000 }" (Misc.print_stack stack);
let stack = Misc.push stack p2 in
assert_equal ~msg:"Test Misc.stack.push2 failed"
"{ a=-0.200000 b=0.400000 c=0.700000 }{ a=1.200000 b=0.300000 c=0.500000 }"
(Misc.print_stack stack);
let stack = Misc.pop stack in
assert_equal ~msg:"Test Misc.stack.pop1 failed"
"{ a=1.200000 b=0.300000 c=0.500000 }" (Misc.print_stack stack);
let stack = Misc.pop stack in
assert_equal ~msg:"Test Misc.stack.pop2 failed" ""
(Misc.print_stack stack);
let stack = Misc.pop stack in
assert_equal ~msg:"Test Misc.stack.pop3 failed" ""
(Misc.print_stack stack);
);
"misc" >:: ( fun test_ctxt ->
assert_equal ~msg:"Test Misc.misc.1 failed" (Sys.getenv "HOME")
Misc.home;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment