Commits

Paweł Wieczorek committed d5f55f3

Added Unittests

Comments (0)

Files changed (5)

 	${CTAGS_CMD} -f ${TAGS_FILE} -R source 
 
 ${PROGRAM}: ${AUTOGEN}
-	${VERBOSE}${OCAMLBUILD_CMD} source/Bin/${PROGRAM}/${PROGRAM}.native source/Bin/Tmp/Tmp.native 
+	${VERBOSE}${OCAMLBUILD_CMD} source/Bin/${PROGRAM}/${PROGRAM}.native source/Bin/Tmp/Tmp.native unittests/Unittests.native
 
 ${AUTOGEN}: Makefile ${SRCS}
 	@echo "	AUTOGEN		${AUTOGEN}"
 <source/**/*>: package(batteries), package(stringpainter), package(commandtree), thread, package(commandtree)
-<test/**/*>: package(batteries), package(stringpainter), package(commandtree), thread, package(commandtree), package(oUnit)
+<unittests/**/*>: package(batteries), package(stringpainter), package(commandtree), thread, package(commandtree), package(oUnit)
 
 <**/*>: annot
 

unittests/Unittests.ml

+open OUnit
+
+let tests = "Opifex" >:::
+    [ "Test_FrozenHashtbl.ml" >::: Test_FrozenHashtbl.tests
+    ]
+
+let _ =
+    run_test_tt_main tests

unittests/Utilities/Test_FrozenHashtbl.ml

+(*
+ * Opifex
+ *
+ * Copyrights(C) 2012,2013 by Pawel Wieczorek <wieczyk at gmail>
+ *)
+
+open OUnit
+
+(*********************************************************************************************************************
+ * Helpers
+ ********************************************************************************************************************)
+
+let create_hashtbl () = 
+    let hl = Hashtbl.create 7 in
+    Hashtbl.add hl 1 10;
+    Hashtbl.add hl 2 20;
+    Hashtbl.add hl 1 100;
+    hl
+
+let create_frozenhashtbl () =
+    FrozenHashtbl.freeze (create_hashtbl ())
+
+(*********************************************************************************************************************
+ * Tests
+ ********************************************************************************************************************)
+
+let test_create = "freeze" >:: begin fun _ -> 
+    ignore (create_frozenhashtbl ())
+    end
+    
+
+let test_find_1 = "find_1" >:: begin fun _ ->
+        let fhl = create_frozenhashtbl () in
+        let x   = FrozenHashtbl.find fhl 1 in
+        assert_equal 100 x
+    end
+
+let test_find_2 = "find_2" >:: begin fun _ ->
+        let fhl = create_frozenhashtbl () in
+        let x   = FrozenHashtbl.find fhl 2 in
+        assert_equal 20 x
+    end
+
+let test_find_notfound = "find_notfound" >:: begin fun _ ->
+        let fhl = create_frozenhashtbl () in
+        assert_raises Not_found (fun () -> FrozenHashtbl.find fhl 3)
+    end
+
+(*********************************************************************************************************************
+ * Test suite
+ ********************************************************************************************************************)
+
+let tests =
+    [ test_create
+    ; test_find_1
+    ; test_find_2
+    ; test_find_notfound
+    ]
+"Utilities": include
+"Languages" : include
+"Libraries" : include
+"Machines" : include