udpated tests

This commit is contained in:
Simon Cruanes 2014-05-22 23:58:36 +02:00
parent 6cc51a77c8
commit b72f8683ce
19 changed files with 126 additions and 96 deletions

30
_oasis
View file

@ -77,15 +77,15 @@ Library "containers_thread"
XMETARequires: containers,threads,lwt XMETARequires: containers,threads,lwt
Library "containers_lwt" Library "containers_lwt"
Path: . Path: lwt
Modules: Behavior, Lwt_automaton Modules: Behavior, Lwt_automaton
Pack: true Pack: true
FindlibName: lwt FindlibName: lwt
FindlibParent: containers FindlibParent: containers
Build$: flag(lwt) Build$: flag(lwt) && flag(misc)
Install$: flag(lwt) Install$: flag(lwt) && flag(misc)
BuildDepends: containers,lwt,lwt.unix BuildDepends: containers,lwt,lwt.unix,containers.misc
XMETARequires: containers,lwt,lwt.unix XMETARequires: containers,lwt,lwt.unix,containers.misc
Library "containers_cgi" Library "containers_cgi"
Path: cgi Path: cgi
@ -137,6 +137,22 @@ Executable test_levenshtein
MainIs: test_levenshtein.ml MainIs: test_levenshtein.ml
BuildDepends: containers,qcheck BuildDepends: containers,qcheck
Executable test_lwt
Path: tests/lwt/
Install: false
CompiledObject: best
Build$: flag(tests) && flag(lwt)
MainIs: test_Behavior.ml
BuildDepends: containers,lwt,lwt.unix,oUnit,containers.lwt
Executable test_threads
Path: tests/lwt/
Install: false
CompiledObject: best
Build$: flag(tests) && flag(thread)
MainIs: test_Future.ml
BuildDepends: containers,threads,oUnit,containers.lwt
Test all Test all
Command: $run_tests Command: $run_tests
TestTools: run_tests TestTools: run_tests
@ -147,8 +163,8 @@ Executable run_tests
Install: false Install: false
CompiledObject: native CompiledObject: native
MainIs: run_tests.ml MainIs: run_tests.ml
Build$: flag(tests) && flag(lwt) Build$: flag(tests)
BuildDepends: containers, oUnit, lwt, threads, lwt.unix BuildDepends: containers, oUnit
Executable web_pwd Executable web_pwd
Path: examples/cgi/ Path: examples/cgi/

View file

@ -3,15 +3,11 @@
let print_int_list l = let print_int_list l =
let b = Buffer.create 20 in let b = Buffer.create 20 in
Format.bprintf b "@[<h>[%a]@]" CCList.pp CCInt.pp b l;
(Sequence.pp_seq ~sep:", " Format.pp_print_int)
(Sequence.of_list l);
Buffer.contents b Buffer.contents b
let print_int_int_list l = let print_int_int_list l =
let printer fmt (i,j) = Format.fprintf fmt "%d, %d" i j in let printer fmt (i,j) = Format.fprintf fmt "%d, %d" i j in
let b = Buffer.create 20 in let b = Buffer.create 20 in
Format.bprintf b "@[<h>[%a]@]" CCList.pp (CCPair.pp CCInt.pp CCInt.pp) b l;
(Sequence.pp_seq ~sep:", " printer)
(Sequence.of_list l);
Buffer.contents b Buffer.contents b

View file

@ -8,7 +8,6 @@ let suite =
Test_PersistentHashtbl.suite; Test_PersistentHashtbl.suite;
Test_bencode.suite; Test_bencode.suite;
Test_bv.suite; Test_bv.suite;
Test_Behavior.suite;
Test_PiCalculus.suite; Test_PiCalculus.suite;
Test_splayMap.suite; Test_splayMap.suite;
Test_bij.suite; Test_bij.suite;
@ -24,7 +23,6 @@ let suite =
Test_heap.suite; Test_heap.suite;
Test_graph.suite; Test_graph.suite;
Test_univ.suite; Test_univ.suite;
Test_future.suite;
] ]
let props = let props =

View file

@ -1,8 +1,8 @@
open OUnit open OUnit
module H = PersistentHashtbl.Make(struct type t = int let equal = (=) let hash i = i end) module H = CCPersistentHashtbl.Make(CCInt)
open Sequence.Infix module Sequence = CCSequence
let test_add () = let test_add () =
let h = H.create 32 in let h = H.create 32 in
@ -50,7 +50,7 @@ let test_persistent () =
let test_big () = let test_big () =
let n = 10000 in let n = 10000 in
let seq = Sequence.map (fun i -> i, string_of_int i) (0--n) in let seq = Sequence.map (fun i -> i, string_of_int i) Sequence.(0--n) in
let h = H.of_seq seq in let h = H.of_seq seq in
(* (*
Format.printf "@[<v2>table:%a@]@." (Sequence.pp_seq Format.printf "@[<v2>table:%a@]@." (Sequence.pp_seq

View file

@ -1,10 +1,11 @@
open OUnit open OUnit
module Sequence = CCSequence
let pp_int_list l = let pp_int_list l =
let b = Buffer.create 4 in let b = Buffer.create 4 in
Format.fprintf (Format.formatter_of_buffer b) "%a@?" CCList.pp CCInt.pp b l;
(Sequence.pp_seq Format.pp_print_int) (Sequence.of_list l);
Buffer.contents b Buffer.contents b
let test_intlist n () = let test_intlist n () =

View file

@ -1,64 +1,66 @@
open OUnit open OUnit
module Sequence = CCSequence
let test_cardinal () = let test_cardinal () =
let bv1 = BV.create ~size:87 true in let bv1 = CCBV.create ~size:87 true in
assert_equal ~printer:string_of_int 87 (BV.cardinal bv1); assert_equal ~printer:string_of_int 87 (CCBV.cardinal bv1);
() ()
let test_get () = let test_get () =
let bv = BV.create ~size:99 false in let bv = CCBV.create ~size:99 false in
assert_bool "32 must be false" (not (BV.get bv 32)); assert_bool "32 must be false" (not (CCBV.get bv 32));
assert_bool "88 must be false" (not (BV.get bv 88)); assert_bool "88 must be false" (not (CCBV.get bv 88));
assert_bool "5 must be false" (not (BV.get bv 5)); assert_bool "5 must be false" (not (CCBV.get bv 5));
BV.set bv 32; CCBV.set bv 32;
BV.set bv 88; CCBV.set bv 88;
BV.set bv 5; CCBV.set bv 5;
assert_bool "32 must be true" (BV.get bv 32); assert_bool "32 must be true" (CCBV.get bv 32);
assert_bool "88 must be true" (BV.get bv 88); assert_bool "88 must be true" (CCBV.get bv 88);
assert_bool "5 must be true" (BV.get bv 5); assert_bool "5 must be true" (CCBV.get bv 5);
assert_bool "33 must be false" (not (BV.get bv 33)); assert_bool "33 must be false" (not (CCBV.get bv 33));
assert_bool "44 must be false" (not (BV.get bv 44)); assert_bool "44 must be false" (not (CCBV.get bv 44));
assert_bool "1 must be false" (not (BV.get bv 1)); assert_bool "1 must be false" (not (CCBV.get bv 1));
() ()
let test_list () = let test_list () =
let bv = BV.of_list [1; 5; 156; 0; 222] in let bv = CCBV.of_list [1; 5; 156; 0; 222] in
assert_equal ~printer:string_of_int 5 (BV.cardinal bv); assert_equal ~printer:string_of_int 5 (CCBV.cardinal bv);
BV.set bv 201; CCBV.set bv 201;
assert_equal ~printer:string_of_int 6 (BV.cardinal bv); assert_equal ~printer:string_of_int 6 (CCBV.cardinal bv);
let l = BV.to_list bv in let l = CCBV.to_list bv in
let l = List.sort compare l in let l = List.sort compare l in
assert_equal [0;1;5;156;201;222] l; assert_equal [0;1;5;156;201;222] l;
() ()
let test_clear () = let test_clear () =
let bv = BV.of_list [1; 5; 200] in let bv = CCBV.of_list [1; 5; 200] in
assert_equal ~printer:string_of_int 3 (BV.cardinal bv); assert_equal ~printer:string_of_int 3 (CCBV.cardinal bv);
BV.clear bv; CCBV.clear bv;
assert_equal ~printer:string_of_int 0 (BV.cardinal bv); assert_equal ~printer:string_of_int 0 (CCBV.cardinal bv);
assert_bool "must be empty" (BV.is_empty bv); assert_bool "must be empty" (CCBV.is_empty bv);
() ()
let test_union () = let test_union () =
let bv1 = BV.of_list [1;2;3;4] in let bv1 = CCBV.of_list [1;2;3;4] in
let bv2 = BV.of_list [4;200;3] in let bv2 = CCBV.of_list [4;200;3] in
let bv = BV.union bv1 bv2 in let bv = CCBV.union bv1 bv2 in
let l = List.sort compare (BV.to_list bv) in let l = List.sort compare (CCBV.to_list bv) in
assert_equal [1;2;3;4;200] l; assert_equal [1;2;3;4;200] l;
() ()
let test_inter () = let test_inter () =
let bv1 = BV.of_list [1;2;3;4] in let bv1 = CCBV.of_list [1;2;3;4] in
let bv2 = BV.of_list [4;200;3] in let bv2 = CCBV.of_list [4;200;3] in
BV.inter_into ~into:bv1 bv2; CCBV.inter_into ~into:bv1 bv2;
let l = List.sort compare (BV.to_list bv1) in let l = List.sort compare (CCBV.to_list bv1) in
assert_equal [3;4] l; assert_equal [3;4] l;
() ()
let test_select () = let test_select () =
let bv = BV.of_list [1;2;5;400] in let bv = CCBV.of_list [1;2;5;400] in
let arr = [|"a"; "b"; "c"; "d"; "e"; "f"|] in let arr = [|"a"; "b"; "c"; "d"; "e"; "f"|] in
let l = List.sort compare (BV.selecti bv arr) in let l = List.sort compare (CCBV.selecti bv arr) in
assert_equal [("b",1); ("c",2); ("f",5)] l; assert_equal [("b",1); ("c",2); ("f",5)] l;
() ()
@ -76,21 +78,21 @@ open QCheck
let check_create_cardinal = let check_create_cardinal =
let gen = Arbitrary.small_int in let gen = Arbitrary.small_int in
let prop n = BV.cardinal (BV.create ~size:n true) = n in let prop n = CCBV.cardinal (CCBV.create ~size:n true) = n in
let name = "bv_create_cardinal" in let name = "bv_create_cardinal" in
mk_test ~name ~pp:string_of_int gen prop mk_test ~name ~pp:string_of_int gen prop
let pp bv = PP.(list string) (List.map string_of_int (BV.to_list bv)) let pp bv = PP.(list string) (List.map string_of_int (CCBV.to_list bv))
let check_iter_true = let check_iter_true =
let gen = Arbitrary.(lift BV.of_list (list small_int)) in let gen = Arbitrary.(lift CCBV.of_list (list small_int)) in
let prop bv = let prop bv =
let l' = Sequence.to_rev_list (BV.iter_true bv) in let l' = Sequence.to_rev_list (CCBV.iter_true bv) in
let bv' = BV.of_list l' in let bv' = CCBV.of_list l' in
BV.cardinal bv = BV.cardinal bv' CCBV.cardinal bv = CCBV.cardinal bv'
in in
let name = "bv_iter_true" in let name = "bv_iter_true" in
mk_test ~pp ~size:BV.cardinal ~name gen prop mk_test ~pp ~size:CCBV.cardinal ~name gen prop
let props = let props =
[ check_create_cardinal [ check_create_cardinal

View file

@ -1,17 +1,18 @@
open OUnit open OUnit
open Sequence.Infix module Deque = CCDeque
module Sequence = CCSequence
let plist l = Utils.sprintf "%a" (Sequence.pp_seq Format.pp_print_int) (Sequence.of_list l) let plist l = CCPrint.to_string (CCList.pp CCInt.pp) l
let pint i = string_of_int i let pint i = string_of_int i
let test_length () = let test_length () =
let d = Deque.of_seq (1 -- 10) in let d = Deque.of_seq Sequence.(1 -- 10) in
OUnit.assert_equal ~printer:pint 10 (Deque.length d) OUnit.assert_equal ~printer:pint 10 (Deque.length d)
let test_front () = let test_front () =
let d = Deque.of_seq (1 -- 10) in let d = Deque.of_seq Sequence.(1 -- 10) in
let printer = pint in let printer = pint in
OUnit.assert_equal ~printer 1 (Deque.peek_front d); OUnit.assert_equal ~printer 1 (Deque.peek_front d);
Deque.push_front d 42; Deque.push_front d 42;
@ -24,7 +25,7 @@ let test_front () =
() ()
let test_back () = let test_back () =
let d = Deque.of_seq (1 -- 10) in let d = Deque.of_seq Sequence.(1 -- 10) in
let printer = pint in let printer = pint in
OUnit.assert_equal ~printer 1 (Deque.peek_front d); OUnit.assert_equal ~printer 1 (Deque.peek_front d);
Deque.push_back d 42; Deque.push_back d 42;
@ -37,7 +38,7 @@ let test_back () =
() ()
let test_iter () = let test_iter () =
let d = Deque.of_seq (1 -- 5) in let d = Deque.of_seq Sequence.(1 -- 5) in
let s = Sequence.from_iter (fun k -> Deque.iter k d) in let s = Sequence.from_iter (fun k -> Deque.iter k d) in
let l = Sequence.to_list s in let l = Sequence.to_list s in
OUnit.assert_equal ~printer:plist [1;2;3;4;5] l; OUnit.assert_equal ~printer:plist [1;2;3;4;5] l;

View file

@ -1,6 +1,8 @@
open OUnit open OUnit
module Sequence = CCSequence
module Test(SomeHashtbl : FHashtbl.S with type key = int) = struct module Test(SomeHashtbl : FHashtbl.S with type key = int) = struct
let test_add () = let test_add () =
let h = SomeHashtbl.empty 32 in let h = SomeHashtbl.empty 32 in

View file

@ -1,6 +1,9 @@
open OUnit open OUnit
module FQueue = CCFQueue
module Sequence = CCSequence
let test_empty () = let test_empty () =
let q = FQueue.empty in let q = FQueue.empty in
OUnit.assert_bool "is_empty" (FQueue.is_empty q) OUnit.assert_bool "is_empty" (FQueue.is_empty q)

View file

@ -1,6 +1,8 @@
open OUnit open OUnit
module Sequence = CCSequence
module IHashtbl = FlatHashtbl.Make(struct module IHashtbl = FlatHashtbl.Make(struct
type t = int type t = int
let equal i j = i = j let equal i j = i = j

View file

@ -1,14 +1,14 @@
open OUnit open OUnit
open Gen.Infix
module Gen = CCGen
module GR = Gen.Restart module GR = Gen.Restart
let pint i = string_of_int i let pint i = string_of_int i
let plist l = Utils.sprintf "%a" let plist l =
(Sequence.pp_seq Format.pp_print_int) (Sequence.of_list l) CCPrint.to_string (CCList.pp CCInt.pp) l
let pstrlist l = Utils.sprintf "%a" let pstrlist l =
(Sequence.pp_seq Format.pp_print_string) (Sequence.of_list l) CCPrint.to_string (CCList.pp Buffer.add_string) l
let test_singleton () = let test_singleton () =
let gen = Gen.singleton 42 in let gen = Gen.singleton 42 in
@ -26,35 +26,35 @@ let test_iter () =
() ()
let test_map () = let test_map () =
let e = 1 -- 10 in let e = Gen.(1 -- 10) in
let e' = Gen.map string_of_int e in let e' = Gen.map string_of_int e in
OUnit.assert_equal ~printer:pstrlist ["9"; "10"] (Gen.to_list (Gen.drop 8 e')); OUnit.assert_equal ~printer:pstrlist ["9"; "10"] (Gen.to_list (Gen.drop 8 e'));
() ()
let test_append () = let test_append () =
let e = Gen.append (1 -- 5) (6 -- 10) in let e = Gen.append Gen.(1 -- 5) Gen.(6 -- 10) in
OUnit.assert_equal [10;9;8;7;6;5;4;3;2;1] (Gen.to_rev_list e); OUnit.assert_equal [10;9;8;7;6;5;4;3;2;1] (Gen.to_rev_list e);
() ()
let test_flatMap () = let test_flatMap () =
let e = 1 -- 3 in let e = Gen.(1 -- 3) in
let e' = e >>= (fun x -> x -- (x+1)) in let e' = Gen.(e >>= (fun x -> x -- (x+1))) in
OUnit.assert_equal [1;2;2;3;3;4] (Gen.to_list e'); OUnit.assert_equal [1;2;2;3;3;4] (Gen.to_list e');
() ()
let test_zip () = let test_zip () =
let e = Gen.zipWith (+) (Gen.repeat 1) (4--7) in let e = Gen.zip_with (+) (Gen.repeat 1) Gen.(4--7) in
OUnit.assert_equal [5;6;7;8] (Gen.to_list e); OUnit.assert_equal [5;6;7;8] (Gen.to_list e);
() ()
let test_filterMap () = let test_filterMap () =
let f x = if x mod 2 = 0 then Some (string_of_int x) else None in let f x = if x mod 2 = 0 then Some (string_of_int x) else None in
let e = Gen.filterMap f (1 -- 10) in let e = Gen.filter_map f Gen.(1 -- 10) in
OUnit.assert_equal ["2"; "4"; "6"; "8"; "10"] (Gen.to_list e); OUnit.assert_equal ["2"; "4"; "6"; "8"; "10"] (Gen.to_list e);
() ()
let test_merge () = let test_merge () =
let e = Gen.of_list [1--3; 4--6; 7--9] in let e = Gen.of_list [Gen.(1--3); Gen.(4--6); Gen.(7--9)] in
let e' = Gen.merge e in let e' = Gen.merge e in
OUnit.assert_equal [1;2;3;4;5;6;7;8;9] (Gen.to_list e' |> List.sort compare); OUnit.assert_equal [1;2;3;4;5;6;7;8;9] (Gen.to_list e' |> List.sort compare);
() ()
@ -99,15 +99,16 @@ let test_interleave () =
() ()
let test_intersperse () = let test_intersperse () =
let e = 1 -- 5 in let e = Gen.(1 -- 5) in
let e' = Gen.intersperse 0 e in let e' = Gen.intersperse 0 e in
OUnit.assert_equal [1;0;2;0;3;0;4;0;5] (Gen.to_list e'); OUnit.assert_equal [1;0;2;0;3;0;4;0;5] (Gen.to_list e');
() ()
let test_product () = let test_product () =
let printer = Helpers.print_int_int_list in let printer = Helpers.print_int_int_list in
let e = Gen.product (1--3) (4--5) in let e = Gen.product Gen.(1--3) Gen.(4--5) in
OUnit.assert_equal ~printer [1,4; 1,5; 2,4; 2,5; 3,4; 3,5] (List.sort compare (Gen.to_list e)); OUnit.assert_equal ~printer [1,4; 1,5; 2,4; 2,5; 3,4; 3,5]
(List.sort compare (Gen.to_list e));
() ()
let suite = let suite =

View file

@ -4,6 +4,7 @@
open OUnit open OUnit
open Helpers open Helpers
module Sequence = CCSequence
module G = PersistentGraph module G = PersistentGraph
(* build a graph from a list of pairs of ints *) (* build a graph from a list of pairs of ints *)
@ -65,11 +66,9 @@ let test_bfs () =
let rec pp_path p = let rec pp_path p =
let buf = Buffer.create 10 in let buf = Buffer.create 10 in
Format.bprintf buf "%a" (Sequence.pp_seq ~sep:"; " pp_edge) CCPrint.to_string (CCList.pp ~sep:"; " pp_edge) p
(Sequence.of_list p); and pp_edge b (v1,e,v2) =
Buffer.contents buf Printf.bprintf b "%d -> %d" v1 v2
and pp_edge formatter (v1,e,v2) =
Format.fprintf formatter "%d -> %d" v1 v2
let test_dijkstra () = let test_dijkstra () =
let g = mk_graph [0,1; 1,2; 2,3; 3,4; 3,0; 4,5; 1,5; 5,6; 4,6; 6,0] in let g = mk_graph [0,1; 1,2; 2,3; 3,4; 3,0; 4,5; 1,5; 5,6; 4,6; 6,0] in

View file

@ -2,6 +2,7 @@
open OUnit open OUnit
open Helpers open Helpers
module Sequence = CCSequence
let test_empty () = let test_empty () =
let h = Heap.empty ~cmp:(fun x y -> x - y) in let h = Heap.empty ~cmp:(fun x y -> x - y) in

View file

@ -3,6 +3,9 @@
open OUnit open OUnit
module Leftistheap = CCLeftistheap
module Sequence = CCSequence
let empty = Leftistheap.empty let empty = Leftistheap.empty
let test1 () = let test1 () =

View file

@ -1,6 +1,8 @@
open OUnit open OUnit
module Sequence = CCSequence
let test_add () = let test_add () =
let h = PHashtbl.create 5 in let h = PHashtbl.create 5 in
PHashtbl.replace h 42 "foo"; PHashtbl.replace h 42 "foo";

View file

@ -1,6 +1,8 @@
open OUnit open OUnit
module Sequence = CCSequence
let test1 () = let test1 () =
let empty = SplayMap.empty () in let empty = SplayMap.empty () in
let m = SplayMap.of_seq empty (Sequence.of_list [1, "1"; 2, "2"; 3, "3"]) in let m = SplayMap.of_seq empty (Sequence.of_list [1, "1"; 2, "2"; 3, "3"]) in

View file

@ -1,10 +1,11 @@
open OUnit open OUnit
open Sequence.Infix module Vector = CCVector
module Sequence = CCSequence
let test_clear () = let test_clear () =
let v = Vector.of_seq (1 -- 10) in let v = Vector.of_seq Sequence.(1 -- 10) in
OUnit.assert_equal 10 (Vector.size v); OUnit.assert_equal 10 (Vector.size v);
Vector.clear v; Vector.clear v;
OUnit.assert_equal 0 (Vector.size v); OUnit.assert_equal 0 (Vector.size v);
@ -12,16 +13,16 @@ let test_clear () =
() ()
let test_append () = let test_append () =
let a = Vector.of_seq (1 -- 5) in let a = Vector.of_seq Sequence.(1 -- 5) in
let b = Vector.of_seq (6 -- 10) in let b = Vector.of_seq Sequence.(6 -- 10) in
Vector.append a b; Vector.append a b;
OUnit.assert_equal 10 (Vector.size a); OUnit.assert_equal 10 (Vector.size a);
OUnit.assert_equal (Sequence.to_array (1 -- 10)) (Vector.to_array a); OUnit.assert_equal (Sequence.to_array Sequence.(1 -- 10)) (Vector.to_array a);
OUnit.assert_equal (Sequence.to_array (6 -- 10)) (Vector.to_array b); OUnit.assert_equal (Sequence.to_array Sequence.(6 -- 10)) (Vector.to_array b);
() ()
let test_copy () = let test_copy () =
let v = Vector.of_seq (1 -- 100) in let v = Vector.of_seq Sequence.(1 -- 100) in
OUnit.assert_equal 100 (Vector.size v); OUnit.assert_equal 100 (Vector.size v);
let v' = Vector.copy v in let v' = Vector.copy v in
OUnit.assert_equal 100 (Vector.size v'); OUnit.assert_equal 100 (Vector.size v');
@ -31,7 +32,7 @@ let test_copy () =
() ()
let test_shrink () = let test_shrink () =
let v = Vector.of_seq (1 -- 10) in let v = Vector.of_seq Sequence.(1 -- 10) in
Vector.shrink v 5; Vector.shrink v 5;
OUnit.assert_equal [1;2;3;4;5] (Vector.to_list v); OUnit.assert_equal [1;2;3;4;5] (Vector.to_list v);
() ()