我有〜10個函數,我想寫測試,它們都採用相同類型的兩個參數。我認爲我可以自動化一些過程,創建所有可能的輸入類的列表,並將所有可能的變體重複打印到文本文件中。我的代碼很不完整,只列出了以「a」開頭的變體。OCaml - 找到所有可能的變化與重複
let x = ["a "; "b "; "c "; "d "; "e "; "f "; "g "; "h "]
let oc = open_out file
let rec test l1 l2 =
match l1 with
|[] -> 0
|h1::t1 ->
match l2 with
|[] -> test t1 l2
|h2::t2 ->
fprintf oc "%s\n" (add^h1^h2);
fprintf oc "%s\n" (sub^h1^h2);
fprintf oc "%s\n" (mul^h1^h2);
fprintf oc "%s\n" (div^h1^h2);
test l1 t2;;
test x x;
close_out oc;