1. Alan Falloon
  2. ocaml-quickcheck

Commits

Alan Falloon  committed acb0ad0

Adding a test that tests the properies of the List module

  • Participants
  • Parent commits 0d2fb4c
  • Branches default

Comments (0)

Files changed (2)

File Makefile

View file
  • Ignore whitespace
 OCAMLC=ocamlc
-quickCheck.cmo: quickCheck.ml
+
+test_List: quickCheck.cmo test_List.cmo
+	$(OCAMLC) -g -o $@ $^
+
+test_List.cmo: quickCheck.cmi
+
+%.cmi: %.mli
 	$(OCAMLC) -c -g -dtypes -o $@ $< $(OUTPUT_PROCESSING)
+
+%.cmo %.cmi: %.ml
+	$(OCAMLC) -c -g -dtypes -o $(@:%.cmi=%.cmo) $< $(OUTPUT_PROCESSING)
+
 OUTPUT_PROCESSING:=$(if $(FLYMAKE), | sed -e '/:$$/{N;s%\n% %;}',)

File test_List.ml

View file
  • Ignore whitespace
+open QuickCheck
+
+module PShow_list(Elt:PSHOW) = struct
+  type t = Elt.t list
+  let show : t -> pretty_str =
+    fun xs fmt () ->
+      let pp = Format.fprintf in
+      match List.map Elt.show xs with
+          [] -> pp fmt "[]"
+        | a1::an ->
+            let pprest f =
+              List.iter (fun e -> pp f ";@ %a" e ())
+            in
+	    pp fmt "[%a%a]" a1 () pprest an
+end
+
+module PShow_char = struct
+  type t = char
+  let show : t -> pretty_str =
+    fun c fmt () ->
+      Format.fprintf fmt "%C" c
+end
+
+let prop_revrev : char list -> bool =
+  fun xs -> List.rev (List.rev xs) = xs
+
+module Arbitrary_char_list =
+  Arbitrary_list(Arbitrary_char)
+module PShow_char_list =
+  PShow_list(PShow_char)
+module Testable_char_list_to_bool =
+  Testable_fun
+    (Arbitrary_char_list)
+    (PShow_char_list)
+    (Testable_bool)
+module C = Check(Testable_char_list_to_bool)
+let () = C.verboseCheck prop_revrev