Commit bef0f118 authored by Julien Lopez's avatar Julien Lopez

All tests for interface are now in OUnit

parent 6d121fbf
CAML=ocamlc -I $@
CDUCE=../../cduce -I $@
CDO2ML=$(CDUCE) --mlstub
OUNIT_TESTS=a eval cdnum cdsdl
RM=rm -f
all: a cdsdl cdmysql eval cdnum
all: $(OUNIT_TESTS)
a:
$(CAML) -c $@/$@.mli
$(CDUCE) --compile $@/c.cd
$(CDUCE) --compile $@/$@.cd
$(CDO2ML) $@/c.cdo > c.ml
$(CDO2ML) $@/c.cdo > $@/c.ml
$(CDO2ML) $@/$@.cdo > $@/$@.ml
ocamlfind $(CAML) -g -package cduce,oUnit -linkpkg -o $@/$@ c.ml $@/$@.ml $@/$@test.ml
./$@/$@
cdsdl:
$(CAML) -c -I `ocamlfind query sdl` $@/$@.mli
$(CDUCE) --compile -I `ocamlfind query sdl` $@/$@.cd
$(CDO2ML) -I `ocamlfind query sdl` $@/$@.cdo > $@/$@.ml
ocamlfind $(CAML) -package cduce,sdl,oUnit -linkpkg -o $@/$@ $@/$@.ml $@/$@test.ml
ocamlfind $(CAML) -g -package cduce,oUnit -linkpkg -o $@/$@ $@/c.ml $@/$@.ml $@/$@test.ml
./$@/$@
eval:
$(CDUCE) --compile $@/$@.cd -I `ocamlfind query cduce`
ocamlfind $(CAML) -o $@/$@ -pp "$(CDO2ML)" -impl $@/$@.cdo -package cduce -linkpkg
$(CAML) -c $@/$@.mli
$(CDUCE) --compile $@/$@.cd -I $(OCAML_TOPLEVEL_PATH)/../cduce
$(CDO2ML) $@/$@.cdo > $@/$@.ml
ocamlfind $(CAML) -I $@ -package cduce,oUnit -linkpkg -o $@/$@ $@/$@.ml $@/$@test.ml
./$@/$@
cdnum:
......@@ -32,11 +29,16 @@ cdnum:
ocamlfind $(CAML) -I $@ -package cduce,num,oUnit -linkpkg -o $@/$@ $@/$@.ml $@/$@test.ml
./$@/$@
cdsdl:
$(CAML) -c -I `ocamlfind query sdl` $@/$@.mli
$(CDUCE) --compile -I `ocamlfind query sdl` $@/$@.cd
$(CDO2ML) -I `ocamlfind query sdl` $@/$@.cdo > $@/$@.ml
ocamlfind $(CAML) -package cduce,sdl,oUnit -linkpkg -o $@/$@ $@/$@.ml $@/$@test.ml
./$@/$@
clean:
find . -name '*.c[dm][oxi]' -delete
find . -name '*.o' -delete
find . -name 'oUnit-*' -delete
rm -f a/a.ml a/c.ml cdnum/cdnum cdnum/cdnum.ml cdsdl/cdsdl.ml eval/eval cdsdl/cdsdl a/a
$(RM) oUnit-* a/c.ml a/c.cdo a/c.cmi a/c.cmo
for i in $(OUNIT_TESTS); do $(RM) `echo $$i/$$i $$i/$$i.ml $$i/$$i.c[dm][oxi] $$i/$${i}test.cm[io]`; done
check:
./check.sh
......
......@@ -17,86 +17,87 @@ 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 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 test_ctxt ->
A.x := 'b';
assert_equal ~msg:"Test A.g.1 failed" 'b' !A.x;
A.g A.x;
assert_equal ~msg:"Test A.g.2 failed" 'a' !A.x;
A.g A.x;
assert_equal ~msg:"Test A.g.3 failed" 'a' !A.x;
);
"re" >:: ( fun test_ctxt ->
assert_equal ~msg:"Test A.re.1 failed" 0.2 (A.re { x=0.2; y=0.8 })
);
"diag" >:: ( fun test_ctxt ->
let res : A.complex = { x=3.14; y=3.14 } in
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)
);
"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
[
"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 test_ctxt ->
A.x := 'b';
assert_equal ~msg:"Test A.g.1 failed" 'b' !A.x;
A.g A.x;
assert_equal ~msg:"Test A.g.2 failed" 'a' !A.x;
A.g A.x;
assert_equal ~msg:"Test A.g.3 failed" 'a' !A.x;
);
"re" >:: ( fun test_ctxt ->
assert_equal ~msg:"Test A.re.1 failed" 0.2 (A.re { A.x=0.2; A.y=0.8 })
);
"diag" >:: ( fun test_ctxt ->
let res : A.complex = { A.x=3.14; A.y=3.14 } in
assert_equal ~msg:"Test A.diag.1 failed" res (A.diag 3.14)
);
"map_complex" >:: ( fun test_ctxt ->
let res : A.complex = { A.x=0.7; A.y=0.7 } in
assert_equal ~msg:"Test A.map_complex.1 failed"
(hypot res.A.x res.A.y) (A.map_complex norm res);
let res2 : A.complex = { A.x=18.6; A.y=4.2 } in
assert_equal ~msg:"Test A.map_complex.2 failed"
(mod_float (res2.A.x, res2.A.y)) (A.map_complex mod_float res2)
);
"pp" >:: ( fun test_ctxt ->
assert_equal ~msg:"Test A.pp.1 failed" "(`C,3)" (A.pp (A.C(3)));
assert_equal ~msg:"Test A.pp.2 failed"
"(`A,(`C,3))" (A.pp (A.A(A.C(3))));
assert_equal ~msg:"Test A.pp.3 failed"
"(`B,((`C,3),(`A,(`C,2))))" (A.pp (A.B(A.C(3),A.A(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 ];
);
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;
);
"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
......@@ -2,15 +2,15 @@ open OUnit2
open Big_int
let tests = "Cdnum" >:::
[
"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)));
);
]
[
"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_main tests
open OUnit2
open Big_int
let tests = "Cdsdl" >:::
[
"sdl_version" >:: ( fun test_ctxt ->
assert_equal ~msg:"Test Cdsdl.sdl_version.1 failed"
(Sdl.string_of_version (Sdl.version ())) (Cdsdl.sdl_version);
);
[
"sdl_version" >:: ( fun test_ctxt ->
try
assert_equal ~msg:"Test Cdsdl.sdl_version.1 failed"
(Sdl.string_of_version (Sdl.version ())) (Cdsdl.sdl_version);
with (ex) -> print_string "SDL exception\n"
);
"sdl_num_drives" >:: ( fun test_ctxt ->
assert_equal ~msg:"Test Cdsdl.sdl_num_drives.1 failed"
(Sdlcdrom.get_num_drives ()) (Cdsdl.sdl_num_drives);
);
"sdl_num_drives" >:: ( fun test_ctxt ->
try
assert_equal ~msg:"Test Cdsdl.sdl_num_drives.1 failed"
(Sdlcdrom.get_num_drives ()) (Cdsdl.sdl_num_drives);
with (ex) -> print_string "SDL exception\n"
);
"sdl_complete_example" >:: ( fun test_ctxt ->
Cdsdl.sdl_init;
let cd = Cdsdl.sdl_cd_open 0 in
Cdsdl.sdl_cd_eject cd;
Cdsdl.sdl_quit ();
);
]
"sdl_complete_example" >:: ( fun test_ctxt ->
try
Cdsdl.sdl_init;
let cd = Cdsdl.sdl_cd_open 0 in
Cdsdl.sdl_cd_eject cd;
Cdsdl.sdl_quit ();
with (ex) -> print_string "SDL exception\n"
);
]
let _ = run_test_tt_main tests
let pr = Cduce_lib.Value.print_utf8
(* TODO: Make this a test when the interface will support polymorphism.
try
let l = Cduce_lib.Cduce.eval
let l = Cduce_lib.Cduce.eval
"let fun f (x : Int) : Int = x + 1;;
let fun g (x : Int) : Int = 2 * x;;
let x = getenv ['HOME'];;
f;; g;;
f;; g;;
let a = g (f 10);;
"
in
let _ = map l with
| ([id], v) ->
| ([id], v) ->
pr [ !(string_of id) ' = ' !(string_of v) '\n' ]
| ([], f & (Int -> Int)) ->
pr [ !(string_of (f 100)) '\n' ]
| ([], v) ->
| ([], v) ->
pr [ !(string_of v) '\n' ]
in []
with (exn & Latin1) ->
print [ 'Exception: ' !exn '\n' ]
*)
val pr : string -> unit
type v = A of (v * v) | B of string
open OUnit2
let tests = "Eval" >:::
[
"misc" >:: ( fun test_ctxt ->
let el = Eval.B("test") in
let el2 = Eval.A(Eval.A(Eval.B("test"),Eval.B("test2")),Eval.B("test3"))
in
let rec to_str x = match x with
| Eval.B(str) -> str
| Eval.A(e1, e2) -> "(" ^ (to_str e1) ^ ", " ^ (to_str e2) ^ ")"
in
assert_equal ~msg:"Test Eval.misc.1 failed" "test" (to_str el);
assert_equal ~msg:"Test Eval.misc.2 failed"
"((test, test2), test3)" (to_str el2);
);
]
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