-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest_minisat.rb
143 lines (121 loc) · 3.24 KB
/
test_minisat.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
require "test/unit"
require "rubygems"
require "minisat"
class TestMiniSat < Test::Unit::TestCase
def setup
@solver = MiniSat::Solver.new
end
def test_variable_pos
var = @solver.new_var
assert_nothing_raised { +var }
end
def test_variable_neg
var = @solver.new_var
assert_nothing_raised { -var }
end
def test_variable_value
var1 = @solver.new_var
var2 = @solver.new_var
assert_raise(RuntimeError) { var1.value }
@solver << var1 << -var2
@solver.solve
assert_equal(true , var1.value)
assert_equal(false, var2.value)
end
def test_solver_add_clause
var1 = @solver.new_var
var2 = @solver.new_var
@solver.add_clause(-var1, -var2)
@solver.add_clause(var1)
@solver.solve
assert_equal(true , var1.value)
assert_equal(false, var2.value)
end
def test_solver_add_clause_2
var1 = @solver.new_var
var2 = @solver.new_var
@solver << [-var1, -var2] << var1
@solver.solve
assert_equal(true , var1.value)
assert_equal(false, var2.value)
end
def test_solver_result
var1 = @solver.new_var
var2 = @solver.new_var
@solver << [-var1, -var2] << var1
@solver.solve
assert_equal(@solver[var1], var1.value)
assert_equal(@solver[var2], var2.value)
end
def test_solver_clause_size
var1 = @solver.new_var
var2 = @solver.new_var
assert_equal(0, @solver.clause_size)
@solver << [-var1, -var2]
assert_equal(1, @solver.clause_size)
@solver << var1
assert_equal(2, @solver.clause_size)
end
def test_solver_satisfied?
assert_equal(false, @solver.satisfied?)
var = @solver.new_var
@solver << var
@solver.solve
assert_equal(true, @solver.satisfied?)
@solver << -var
@solver.solve
assert_equal(false, @solver.satisfied?)
end
def test_solver_simplify_db
@solver.solve
assert_nothing_raised { @solver.simplify_db }
end
def test_solver_solve
var1 = @solver.new_var
var2 = @solver.new_var
@solver << [var1, var2]
assert_equal(false, @solver.solve(-var1, -var2))
assert_equal(true , @solver.solve(-var1))
assert_equal(false, var1.value)
assert_equal(true , var2.value)
end
def test_solver_solved?
assert_equal(false, @solver.solved?)
var = @solver.new_var
@solver << var
@solver.solve
assert_equal(true, @solver.solved?)
@solver << -var
@solver.solve
assert_equal(true, @solver.solved?)
end
def test_var_size
assert_equal(0, @solver.var_size)
var1 = @solver.new_var
assert_equal(1, @solver.var_size)
var2 = @solver.new_var
assert_equal(2, @solver.var_size)
end
def test_senario1
a = @solver.new_var
b = @solver.new_var
@solver << [a, b] << [-a, b] << [a, -b]
assert_equal(true, @solver.solve)
assert_equal(true, @solver[a])
assert_equal(true, @solver[b])
end
def test_senario2
a = @solver.new_var
b = @solver.new_var
@solver << [-a, -b] << [-a, b] << [a, -b]
assert_equal(true, @solver.solve)
assert_equal(false, @solver[a])
assert_equal(false, @solver[b])
end
def test_senario3
a = @solver.new_var
b = @solver.new_var
@solver << [a, b] << [-a, b] << [a, -b] << [-a, -b]
assert_equal(false, @solver.solve)
end
end