Commit 9ddf1e81 authored by Julien Lopez's avatar Julien Lopez

More OUnit tests added

parent 54022296
......@@ -8,14 +8,12 @@ let re (c : { x = Float .. }) : Float = c . x
let diag (x : Float) : { x = Float; y = Float } = { x = x; y = x }
let map_complex (f : (Float,Float)->Float)(c : { x = Float; y = Float })
: Float =
let map_complex (f : (Float,Float)->Float)(c : { x = Float; y = Float })
: Float =
f (c . x, c . y)
let pp (x : Any) : Latin1 = string_of x
let exists = Sys.file_exists
let i = c.j
......@@ -26,11 +24,6 @@ let stdin (* : !Unix.file_descr *) = Unix.stderr
let unix_write = Unix.write
let str_len = String.length
let _ = unix_write stdin home 0 (str_len home)
let [] = Unix.sleep 1
(*let [] = Unix.sleep 1*)
let listmap = List.map with { Int Int }
let lst = listmap (fun (x : Int) : Int = x * 2) [ 10 20 30 ] in
print (string_of lst)
......@@ -19,3 +19,12 @@ val exists : string -> bool
val home : string
val stdin : Unix.file_descr
val unix_write : Unix.file_descr -> string -> int -> int -> int
val str_len : string -> int
type cduce_int = Big_int.big_int
val listmap : (cduce_int -> cduce_int) -> cduce_int list -> cduce_int list
......@@ -49,6 +49,54 @@ let tests = "A" >:::
assert_equal ~msg:"Test A.map_complex.2 failed"
(mod_float (res2.x, res2.y)) (A.map_complex mod_float res2)
);
"pp" >:: ( fun test_ctxt ->
assert_equal ~msg:"Test A.pp.1 failed" "(`C,3)" (A.pp (C(3)));
assert_equal ~msg:"Test A.pp.2 failed" "(`A,(`C,3))" (A.pp (A(C(3))));
assert_equal ~msg:"Test A.pp.3 failed"
"(`B,((`C,3),(`A,(`C,2))))" (A.pp (B(C(3),A(C(2)))));
);
"exists" >:: ( fun test_ctxt ->
assert_equal ~msg:"Test A.exists.1 failed" false (A.exists "toto.tmp");
let file = bracket_tmpfile test_ctxt in match file with
| (name, _) -> assert_equal
~msg:"Test A.exists.2 failed" true (A.exists name);
);
"str_len" >:: ( fun test_ctxt ->
let str = "This is an example." in
assert_equal ~msg:"Test A.str_len.1 failed" 19 (A.str_len str);
assert_equal ~msg:"Test A.str_len.2 failed" 23 (A.str_len (str^"hack"));
);
"unix_write" >:: ( fun test_ctxt ->
let h = Sys.getenv "HOME" in
assert_equal ~msg:"Test A.unix_write.easy failed"
(String.length h) (A.unix_write Unix.stderr h 0 (String.length h));
assert_equal ~msg:"Test A.unix_write.hard failed"
(A.str_len A.home) (A.unix_write A.stdin A.home 0 (A.str_len A.home))
);
"listmap" >:: ( fun test_ctxt ->
let bioi = Big_int.big_int_of_int in
let lst = A.listmap (fun x -> Big_int.mult_int_big_int 2 x)
[ bioi 10; bioi 20; bioi 30 ] in
let rec test_each lst refs = match lst,refs with
| (el :: rest), (el2 :: rest2) -> assert_equal
~msg:"Test A.listmap.1 failed" 0 (Big_int.compare_big_int el el2);
test_each rest rest2
| [], [] -> assert true
| _ -> assert false
in
test_each lst [ bioi 20; bioi 40; bioi 60 ];
);
"misc" >:: ( fun test_ctxt ->
assert_equal ~msg:"Test A.misc.1 failed" (Sys.getenv "HOME") A.home;
assert_equal ~msg:"Test A.misc.2 failed" 2 A.i;
);
]
let _ = run_test_tt_main tests
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