(* CSCI 3155: Project 1: Boolean Formulae: Tests PRACTICE *) val test_to_nnf1 = Or (True, Not (Var "x")) = to_nnf (Not (And (False, Var "x"))) fun test_sat (f: formula) (expected: bool) : bool = case sat f of NONE => expected = false | SOME _ => expected = true val f1 = And (Not (Var "a"), Or (Var "a", Forall ("x", Or (Var "b", Var "x")))) val test_sat1 = test_sat f1 true (* pad : int -> vec -> vec Pads v to length n with Falses. *) fun pad (n: int) (v: vec) : vec = let fun pad' (n, nil, acc) = if n <= 0 then acc else pad' (n - 1, nil, False :: acc) | pad' (n, h :: t, acc) = pad' (n - 1, t, h :: acc) in List.rev (pad' (n, v, [])) end (* vecvar : string -> int -> vec Create a vector consisting of Vars. *) fun vecvar (prefix: string) (n: int) : vec = List.tabulate (n, fn i => Var (prefix ^ (Int.toString i))) val test_is_magic1 = let val $ = (pad 4) o vec_of_int val var = vecvar "b" 4 in case sat (is_magic [$8, $1, $6, $3, var, $7, $4, $9, $2]) of NONE => false | SOME a => (int_of_vec (subst a var)) = 5 end