ocaml-bert / tests_bert.ml

(** tests for bert.ml **)

exception Test_failure;;

let do_tests suite = 
  let rec run_tests my_suite suc = 
    match my_suite with
      | [] -> (suc = List.length suite);
      | hd::tl ->
	  if hd () then run_tests tl (suc+1)
	  else run_tests tl suc 
  in
    run_tests suite 0;;

let rec decoding_test answers problem results=
  match answers, (Bert.decode_binary problem) with
    | [], _ -> results;
    | hd::tl, Bert.Ok( term, remain )->
	print_endline "!!!";
	Bert.print_binary_string problem;
	Bert.print_erlterm term;
	begin if term = hd then
	  decoding_test tl remain (results+1)
	else 
	  raise Test_failure
	end;
    | _ ->
	raise Test_failure;;

let rec encode_all list str ofs =
  match list with
    | [] ->  ofs;
    | hd::tl ->
	let nofs = Bert.encode_term hd str ofs in
	  encode_all tl str nofs;;

let _ = 
  let list = [ Bert.Int(774567); Bert.Float(23.43); Bert.Atom("HAHAHAHA");
	       Bert.String("HAHAHA"); Bert.Binary("HAHAHA") ] in
  let str = String.create 128 in
  let _ = encode_all list str 0 in
    Bert.print_binary_string str;
    decoding_test list str 0 ;;
(*    print_endline str; 
  raise Test_failure;; *)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.