mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 11:15:43 -05:00
New test script.
This commit is contained in:
parent
f1df47c43b
commit
7cd1f38d49
9 changed files with 55 additions and 11 deletions
4
Makefile
4
Makefile
|
|
@ -20,7 +20,9 @@ doc:
|
||||||
$(COMP) $(FLAGS) $(DIRS) $(DOC)
|
$(COMP) $(FLAGS) $(DIRS) $(DOC)
|
||||||
|
|
||||||
test: $(TEST)
|
test: $(TEST)
|
||||||
./tests/main tests/test-0.d
|
|
||||||
|
test-full: $(TEST)
|
||||||
|
./tests/run
|
||||||
|
|
||||||
$(TEST): $(LIB)
|
$(TEST): $(LIB)
|
||||||
$(COMP) $(FLAGS) $(DIRS) $(TEST)
|
$(COMP) $(FLAGS) $(DIRS) $(TEST)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,12 @@ module Fsat = struct
|
||||||
let max_lit = min max_int (- min_int)
|
let max_lit = min max_int (- min_int)
|
||||||
let max_index = ref 0
|
let max_index = ref 0
|
||||||
|
|
||||||
let make i = if i <> 0 then i else raise Dummy
|
let make i =
|
||||||
|
if i <> 0 then begin
|
||||||
|
max_index := max !max_index (abs i);
|
||||||
|
i
|
||||||
|
end else
|
||||||
|
raise Dummy
|
||||||
|
|
||||||
let dummy = 0
|
let dummy = 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ module Make(Dummy: sig end) : sig
|
||||||
|
|
||||||
val make : int -> atom
|
val make : int -> atom
|
||||||
(** Returns the literal corresponding to the integer.
|
(** Returns the literal corresponding to the integer.
|
||||||
@raise bad_atom if given [0] as argument.*)
|
@raise Bad_atom if given [0] as argument.*)
|
||||||
|
|
||||||
val neg : atom -> atom
|
val neg : atom -> atom
|
||||||
(** [neg a] returns the negation of a literal. Involutive, i.e [neg (neg a) = a]. *)
|
(** [neg a] returns the negation of a literal. Involutive, i.e [neg (neg a) = a]. *)
|
||||||
|
|
|
||||||
19
tests/run
Executable file
19
tests/run
Executable file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
solvertest () {
|
||||||
|
for f in `find $1 -name *.d -type f`
|
||||||
|
do
|
||||||
|
echo -ne "\r\033[K Testing $f "
|
||||||
|
tests/main $f | grep $2 > /dev/null 2> /dev/null
|
||||||
|
RET=$?
|
||||||
|
if [ $RET -ne 0 ];
|
||||||
|
then
|
||||||
|
echo -e "\r\033[K\e[31m[KO]\e[0m $f"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo -e "\r\033[K\e[32m[OK]\e[0m $2"
|
||||||
|
}
|
||||||
|
|
||||||
|
solvertest "tests/sat/" "Sat"
|
||||||
|
solvertest "tests/unsat/" "Unsat"
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
c First test
|
c Status: SAT
|
||||||
p cnf 2 1
|
p cnf 2 1
|
||||||
1 2 0
|
1 2 0
|
||||||
8
tests/unsat/test-001.d
Normal file
8
tests/unsat/test-001.d
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
c First test
|
||||||
|
p cnf 5 6
|
||||||
|
1 2 0
|
||||||
|
-1 3 0
|
||||||
|
-2 3 0
|
||||||
|
4 5 0
|
||||||
|
-4 -3 0
|
||||||
|
-5 -3 0
|
||||||
|
|
@ -11,6 +11,6 @@ rule token = parse
|
||||||
| 'p' { P }
|
| 'p' { P }
|
||||||
| "cnf" { CNF }
|
| "cnf" { CNF }
|
||||||
| '\n' { EOL }
|
| '\n' { EOL }
|
||||||
| "c " [^ '\n']* '\n' { token lexbuf }
|
| "c " [^ '\n']* '\n' { token lexbuf }
|
||||||
| ['-']? number { LIT (int_of_string (Lexing.lexeme lexbuf)) }
|
| ['-']? number { LIT (int_of_string (Lexing.lexeme lexbuf)) }
|
||||||
| eof { EOF }
|
| eof { EOF }
|
||||||
|
|
|
||||||
|
|
@ -15,15 +15,16 @@
|
||||||
/* DIMACS syntax */
|
/* DIMACS syntax */
|
||||||
|
|
||||||
file:
|
file:
|
||||||
| EOF { [] }
|
| EOF { [] }
|
||||||
| P CNF LIT LIT EOL clause_list { $6 }
|
| P CNF LIT LIT EOL clause_list { $6 }
|
||||||
;
|
;
|
||||||
clause_list:
|
clause_list:
|
||||||
| EOF { [] }
|
| EOF { [] }
|
||||||
|
| EOL clause_list { $2 }
|
||||||
| clause clause_list { $1 :: $2 }
|
| clause clause_list { $1 :: $2 }
|
||||||
;
|
;
|
||||||
clause:
|
clause:
|
||||||
/* Clause always ends with a '0' */
|
/* clauses always ends with a '0' */
|
||||||
| LIT EOL { if $1 = 0 then [] else raise (Clause_ending $1) }
|
| LIT EOL { if $1 = 0 then [] else raise (Clause_ending $1) }
|
||||||
| LIT clause { $1 :: $2 }
|
| LIT clause { $1 :: $2 }
|
||||||
;
|
;
|
||||||
|
|
|
||||||
17
util/test.ml
17
util/test.ml
|
|
@ -3,12 +3,15 @@ module S = Sat.Make(struct end)
|
||||||
|
|
||||||
(* Arguments parsing *)
|
(* Arguments parsing *)
|
||||||
let file = ref ""
|
let file = ref ""
|
||||||
|
let p_assign = ref false
|
||||||
|
|
||||||
let input_file = fun s -> file := s
|
let input_file = fun s -> file := s
|
||||||
let usage = "Usage : main [options] <file>"
|
let usage = "Usage : main [options] <file>"
|
||||||
let argspec = Arg.align [
|
let argspec = Arg.align [
|
||||||
"-v", Arg.Int (fun i -> Log.set_debug i),
|
"-v", Arg.Int (fun i -> Log.set_debug i),
|
||||||
"<lvl> Sets the debug verbose level";
|
"<lvl> Sets the debug verbose level";
|
||||||
|
"-model", Arg.Set p_assign,
|
||||||
|
" Outputs the boolean model found if sat";
|
||||||
]
|
]
|
||||||
|
|
||||||
(* Entry file parsing *)
|
(* Entry file parsing *)
|
||||||
|
|
@ -33,7 +36,7 @@ let print_assign fmt () =
|
||||||
S.iter_atoms (fun a ->
|
S.iter_atoms (fun a ->
|
||||||
Format.fprintf fmt "%a -> %s,@ "
|
Format.fprintf fmt "%a -> %s,@ "
|
||||||
S.print_atom a
|
S.print_atom a
|
||||||
(if S.eval a then "true" else "false")
|
(if S.eval a then "T" else "F")
|
||||||
)
|
)
|
||||||
|
|
||||||
let main () =
|
let main () =
|
||||||
|
|
@ -43,8 +46,14 @@ let main () =
|
||||||
exit 2
|
exit 2
|
||||||
end;
|
end;
|
||||||
let cnf = get_cnf () in
|
let cnf = get_cnf () in
|
||||||
print_cnf cnf;
|
S.assume cnf;
|
||||||
()
|
match S.solve () with
|
||||||
|
| S.Sat ->
|
||||||
|
Format.printf "Sat@.";
|
||||||
|
if !p_assign then
|
||||||
|
print_assign Format.std_formatter ()
|
||||||
|
| S.Unsat ->
|
||||||
|
Format.printf "Unsat@."
|
||||||
;;
|
;;
|
||||||
|
|
||||||
main ()
|
main ()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue