Commit 54022296 authored by Julien Lopez's avatar Julien Lopez

Updating tests for OUnit v2

parent 1185652b
......@@ -57,7 +57,7 @@ cdnum:
# ./$@
clean:
rm -f *.cmo *.cmx *.o *.cdo *.cmi a.ml c.ml cdnum cdnum.ml eval cdsdl cdmysql a oUnit-anon.cache
rm -f *.cmo *.cmx *.o *.cdo *.cmi a.ml c.ml cdnum cdnum.ml eval cdsdl cdmysql a oUnit-*
check:
./check.sh
open OUnit
open OUnit2
let rot13 b = if (b >= 'a' && b <= 'z') then
let res = int_of_char b+13 in
......@@ -12,30 +12,43 @@ let rot13 b = if (b >= 'a' && b <= 'z') then
let id x = x;;
let norm (x,y) = sqrt(x *. x +. y *. y);;
let mod_float (x,y) = x -. float_of_int(int_of_float (x /. y)) *. y
let tests = "A" >:::
[
"f" >:: ( fun () ->
assert_equal "Hello!" (A.f id "Hello!");
assert_equal "Uryyb!" (A.f rot13 "Hello!")
"f" >:: ( fun test_ctxt ->
assert_equal ~msg:"Test A.f.1 failed" "Hello!" (A.f id "Hello!");
assert_equal ~msg:"Test A.f.2 failed" "Uryyb!" (A.f rot13 "Hello!")
);
"g" >:: ( fun () ->
"g" >:: ( fun test_ctxt ->
A.x := 'b';
assert_equal 'b' !A.x;
assert_equal ~msg:"Test A.g.1 failed" 'b' !A.x;
A.g A.x;
assert_equal 'a' !A.x;
assert_equal ~msg:"Test A.g.2 failed" 'a' !A.x;
A.g A.x;
assert_equal 'a' !A.x;
assert_equal ~msg:"Test A.g.3 failed" 'a' !A.x;
);
"re" >:: ( fun () ->
assert_equal 0.2 (A.re { x=0.2; y=0.8 })
"re" >:: ( fun test_ctxt ->
assert_equal ~msg:"Test A.re.1 failed" 0.2 (A.re { x=0.2; y=0.8 })
);
"diag" >:: ( fun () ->
"diag" >:: ( fun test_ctxt ->
let res : A.complex = { x=3.14; y=3.14 } in
assert_equal res (A.diag 3.14)
assert_equal ~msg:"Test A.diag.1 failed" res (A.diag 3.14)
);
"map_complex" >:: ( fun test_ctxt ->
let res : A.complex = { x=0.7; y=0.7 } in
assert_equal ~msg:"Test A.map_complex.1 failed"
(hypot res.x res.y) (A.map_complex norm res);
let res2 : A.complex = { x=18.6; y=4.2 } in
assert_equal ~msg:"Test A.map_complex.2 failed"
(mod_float (res2.x, res2.y)) (A.map_complex mod_float res2)
);
]
let _ = run_test_tt ~verbose:true tests
let _ = run_test_tt_main tests
open OUnit
open OUnit2
open Big_int
let tests = "Cdnum" >:::
[
"fact" >:: ( fun () ->
assert_equal 2 (int_of_big_int (Cdnum.fact (big_int_of_int 2)));
assert_equal 1 (int_of_big_int (Cdnum.fact (big_int_of_int 0)));
assert_equal 120 (int_of_big_int (Cdnum.fact (big_int_of_int 5)));
"fact" >:: ( fun test_ctxt ->
assert_equal ~msg:"Test Cdnum.fact.1 failed"
2 (int_of_big_int (Cdnum.fact (big_int_of_int 2)));
assert_equal ~msg:"Test Cdnum.fact.2 failed"
1 (int_of_big_int (Cdnum.fact (big_int_of_int 0)));
assert_equal ~msg:"Test Cdnum.fact.3 failed"
120 (int_of_big_int (Cdnum.fact (big_int_of_int 5)));
);
]
let _ = run_test_tt ~verbose:true tests
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