z3 0.0.20220630 → 0.0.20221020
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/z3/expr/array_expr.rb +20 -0
- data/lib/z3/interface.rb +4 -0
- data/lib/z3/optimize.rb +2 -2
- data/spec/array_expr_spec.rb +33 -1
- data/spec/array_sort_spec.rb +2 -2
- data/spec/float_expr_spec.rb +2 -1
- data/spec/integration/abc_path_spec.rb +1 -17
- data/spec/integration/examples/abc_path-1.txt +13 -0
- data/spec/integration/examples/abc_path-2.txt +13 -0
- data/spec/integration/examples/futoshiki-1.txt +17 -0
- data/spec/integration/examples/futoshiki-2.txt +17 -0
- data/spec/integration/examples/knights_puzzle-1.txt +90 -0
- data/spec/integration/examples/knights_puzzle-2.txt +90 -0
- data/spec/integration/examples/knights_puzzle-3.txt +90 -0
- data/spec/integration/examples/knights_puzzle-4.txt +90 -0
- data/spec/integration/futoshiki_spec.rb +1 -19
- data/spec/integration/knights_puzzle_spec.rb +1 -94
- data/spec/optimize_spec.rb +10 -11
- data/spec/set_expr_spec.rb +1 -1
- data/spec/solver_spec.rb +1 -1
- data/spec/spec_helper.rb +14 -0
- data/spec/z3_spec.rb +10 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abba86119ff297f1b65693b634c5f33b11e53ea24f76b5b851d11918bf061694
|
4
|
+
data.tar.gz: bf2253285a83d24d1e7a5264d839506f65b32a45c27203dcf12202daab0c527a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d63a2a62b5f8103eca1c0ae9429a5538cb5a0add23ca14fdceb1759f821d5a0f8ddeb22c06efad3780b5498d8c6ff0fea4f9d0c86c3d1e1dbfd443265f3b4f4a
|
7
|
+
data.tar.gz: 7cd9d08794c1fa4cb2c47575c3977d35a781874c5f27f03ee31eb251e153062f91e8bd38236da887cc1a1fb6e401250038e98cd44d63197e120d84cd8171ef1f
|
data/lib/z3/expr/array_expr.rb
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
module Z3
|
2
2
|
class ArrayExpr < Expr
|
3
3
|
public_class_method :new
|
4
|
+
|
5
|
+
def key_sort
|
6
|
+
sort.key_sort
|
7
|
+
end
|
8
|
+
|
9
|
+
def value_sort
|
10
|
+
sort.value_sort
|
11
|
+
end
|
12
|
+
|
13
|
+
def store(key, value)
|
14
|
+
sort.new LowLevel.mk_store(self, key_sort.cast(key), value_sort.cast(value))
|
15
|
+
end
|
16
|
+
|
17
|
+
def select(key)
|
18
|
+
sort.value_sort.new LowLevel.mk_select(self, key_sort.cast(key))
|
19
|
+
end
|
20
|
+
|
21
|
+
def [](key)
|
22
|
+
select(key)
|
23
|
+
end
|
4
24
|
end
|
5
25
|
end
|
data/lib/z3/interface.rb
CHANGED
data/lib/z3/optimize.rb
CHANGED
@@ -23,9 +23,9 @@ module Z3
|
|
23
23
|
LowLevel.optimize_assert(self, ast)
|
24
24
|
end
|
25
25
|
|
26
|
-
def assert_soft(ast)
|
26
|
+
def assert_soft(ast, weight = "1", id = nil)
|
27
27
|
reset_model!
|
28
|
-
LowLevel.optimize_assert_soft(self, ast)
|
28
|
+
LowLevel.optimize_assert_soft(self, ast, weight, id)
|
29
29
|
end
|
30
30
|
|
31
31
|
def check(*args)
|
data/spec/array_expr_spec.rb
CHANGED
@@ -4,7 +4,9 @@ module Z3
|
|
4
4
|
let(:a) { sort.var("a") }
|
5
5
|
let(:b) { sort.var("b") }
|
6
6
|
let(:c) { sort.var("c") }
|
7
|
-
let(:x) { Z3::
|
7
|
+
let(:x) { Z3::Int("x") }
|
8
|
+
let(:y) { Z3::Int("y") }
|
9
|
+
let(:z) { Z3::Int("z") }
|
8
10
|
|
9
11
|
# TODO: Formatting is dreadful
|
10
12
|
it "== and !=" do
|
@@ -14,5 +16,35 @@ module Z3
|
|
14
16
|
c => "const(0)",
|
15
17
|
)
|
16
18
|
end
|
19
|
+
|
20
|
+
it "select" do
|
21
|
+
expect([a.select(10) == 20]).to have_solution(
|
22
|
+
a => "const(20)",
|
23
|
+
)
|
24
|
+
expect([a[10] == 20]).to have_solution(
|
25
|
+
a => "const(20)",
|
26
|
+
)
|
27
|
+
expect([a[x] == 10, a[y] == 20]).to have_solution(
|
28
|
+
a => "store(const(10), 3, 20)",
|
29
|
+
x => "2",
|
30
|
+
y => "3",
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "store" do
|
35
|
+
expect([a == b.store(10, 20), x == a.select(10)]).to have_solution(
|
36
|
+
x => 20,
|
37
|
+
)
|
38
|
+
expect([a == b.store(10, 20), x == a[10]]).to have_solution(
|
39
|
+
x => 20,
|
40
|
+
)
|
41
|
+
expect([a == b.store(10, 20), x == a[y], y == 10]).to have_solution(
|
42
|
+
x => 20,
|
43
|
+
)
|
44
|
+
expect([a == b.store(10, 20), x == a[y], x == 20]).to have_solution(
|
45
|
+
x => 20,
|
46
|
+
y => 10,
|
47
|
+
)
|
48
|
+
end
|
17
49
|
end
|
18
50
|
end
|
data/spec/array_sort_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Z3
|
2
2
|
describe ArraySort do
|
3
|
-
let(:int_int_array)
|
4
|
-
let(:int_real_array)
|
3
|
+
let(:int_int_array) { ArraySort.new(IntSort.new, IntSort.new) }
|
4
|
+
let(:int_real_array) { ArraySort.new(IntSort.new, RealSort.new) }
|
5
5
|
|
6
6
|
it "can instantiate variables" do
|
7
7
|
expect(int_int_array.var("a").inspect).to eq("Array(Int, Int)<a>")
|
data/spec/float_expr_spec.rb
CHANGED
@@ -102,8 +102,9 @@ module Z3
|
|
102
102
|
expect(positive_infinity.to_s).to eq("+oo")
|
103
103
|
expect(negative_infinity.to_s).to eq("-oo")
|
104
104
|
expect(nan.to_s).to eq("NaN")
|
105
|
+
|
105
106
|
# Denormals changed
|
106
|
-
if Z3.
|
107
|
+
if Z3.version_at_least?(4, 6)
|
107
108
|
expect(float_double.from_const(1234 * 0.5**1040).to_s).to eq("0.00470733642578125B-1022")
|
108
109
|
expect(float_single.from_const(1234 * 0.5**136).to_s).to eq("1.205078125B-126")
|
109
110
|
# This is what we get, all of these are wrong, by a lot:
|
@@ -1,21 +1,5 @@
|
|
1
|
-
# There are multiple solutions, so this test is nondeterministic
|
2
|
-
# This is what Z3 4.8.13 returns
|
3
1
|
describe "ABC Path" do
|
4
2
|
it do
|
5
|
-
expect("abc_path").to
|
6
|
-
C O R D F B U
|
7
|
-
|
8
|
-
N o-n l-k-j L
|
9
|
-
| |/ |
|
10
|
-
G p m g-f i I
|
11
|
-
| x /
|
12
|
-
Q q-r e h a H
|
13
|
-
/ | |
|
14
|
-
V s v d-c-b S
|
15
|
-
x \
|
16
|
-
T u-t w-x-y X
|
17
|
-
|
18
|
-
J P M W K Y E
|
19
|
-
EOF
|
3
|
+
expect("abc_path").to have_output_matching_saved_example
|
20
4
|
end
|
21
5
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
Solved
|
2
|
+
State 0:
|
3
|
+
bbb.
|
4
|
+
xbxw
|
5
|
+
..ww
|
6
|
+
x.xw
|
7
|
+
w: 2,2 -> 3,0
|
8
|
+
|
9
|
+
State 1:
|
10
|
+
bbbw
|
11
|
+
xbxw
|
12
|
+
...w
|
13
|
+
x.xw
|
14
|
+
b: 1,0 -> 2,2
|
15
|
+
|
16
|
+
State 2:
|
17
|
+
b.bw
|
18
|
+
xbxw
|
19
|
+
..bw
|
20
|
+
x.xw
|
21
|
+
w: 3,1 -> 1,0
|
22
|
+
|
23
|
+
State 3:
|
24
|
+
bwbw
|
25
|
+
xbx.
|
26
|
+
..bw
|
27
|
+
x.xw
|
28
|
+
b: 0,0 -> 1,2
|
29
|
+
|
30
|
+
State 4:
|
31
|
+
.wbw
|
32
|
+
xbx.
|
33
|
+
.bbw
|
34
|
+
x.xw
|
35
|
+
b: 1,2 -> 3,1
|
36
|
+
|
37
|
+
State 5:
|
38
|
+
.wbw
|
39
|
+
xbxb
|
40
|
+
..bw
|
41
|
+
x.xw
|
42
|
+
w: 3,3 -> 1,2
|
43
|
+
|
44
|
+
State 6:
|
45
|
+
.wbw
|
46
|
+
xbxb
|
47
|
+
.wbw
|
48
|
+
x.x.
|
49
|
+
w: 1,2 -> 0,0
|
50
|
+
|
51
|
+
State 7:
|
52
|
+
wwbw
|
53
|
+
xbxb
|
54
|
+
..bw
|
55
|
+
x.x.
|
56
|
+
b: 2,0 -> 1,2
|
57
|
+
|
58
|
+
State 8:
|
59
|
+
ww.w
|
60
|
+
xbxb
|
61
|
+
.bbw
|
62
|
+
x.x.
|
63
|
+
w: 3,2 -> 2,0
|
64
|
+
|
65
|
+
State 9:
|
66
|
+
wwww
|
67
|
+
xbxb
|
68
|
+
.bb.
|
69
|
+
x.x.
|
70
|
+
b: 1,1 -> 3,2
|
71
|
+
|
72
|
+
State 10:
|
73
|
+
wwww
|
74
|
+
x.xb
|
75
|
+
.bbb
|
76
|
+
x.x.
|
77
|
+
b: 1,2 -> 3,3
|
78
|
+
|
79
|
+
State 11:
|
80
|
+
wwww
|
81
|
+
x.xb
|
82
|
+
..bb
|
83
|
+
x.xb
|
84
|
+
w: 3,0 -> 1,1
|
85
|
+
|
86
|
+
State 12:
|
87
|
+
www.
|
88
|
+
xwxb
|
89
|
+
..bb
|
90
|
+
x.xb
|
@@ -0,0 +1,90 @@
|
|
1
|
+
Solved
|
2
|
+
State 0:
|
3
|
+
bbb.
|
4
|
+
xbxw
|
5
|
+
..ww
|
6
|
+
x.xw
|
7
|
+
w: 2,2 -> 3,0
|
8
|
+
|
9
|
+
State 1:
|
10
|
+
bbbw
|
11
|
+
xbxw
|
12
|
+
...w
|
13
|
+
x.xw
|
14
|
+
b: 1,0 -> 2,2
|
15
|
+
|
16
|
+
State 2:
|
17
|
+
b.bw
|
18
|
+
xbxw
|
19
|
+
..bw
|
20
|
+
x.xw
|
21
|
+
w: 3,1 -> 1,0
|
22
|
+
|
23
|
+
State 3:
|
24
|
+
bwbw
|
25
|
+
xbx.
|
26
|
+
..bw
|
27
|
+
x.xw
|
28
|
+
b: 0,0 -> 1,2
|
29
|
+
|
30
|
+
State 4:
|
31
|
+
.wbw
|
32
|
+
xbx.
|
33
|
+
.bbw
|
34
|
+
x.xw
|
35
|
+
b: 1,2 -> 3,1
|
36
|
+
|
37
|
+
State 5:
|
38
|
+
.wbw
|
39
|
+
xbxb
|
40
|
+
..bw
|
41
|
+
x.xw
|
42
|
+
w: 3,3 -> 1,2
|
43
|
+
|
44
|
+
State 6:
|
45
|
+
.wbw
|
46
|
+
xbxb
|
47
|
+
.wbw
|
48
|
+
x.x.
|
49
|
+
w: 1,2 -> 0,0
|
50
|
+
|
51
|
+
State 7:
|
52
|
+
wwbw
|
53
|
+
xbxb
|
54
|
+
..bw
|
55
|
+
x.x.
|
56
|
+
b: 2,0 -> 1,2
|
57
|
+
|
58
|
+
State 8:
|
59
|
+
ww.w
|
60
|
+
xbxb
|
61
|
+
.bbw
|
62
|
+
x.x.
|
63
|
+
b: 1,2 -> 3,3
|
64
|
+
|
65
|
+
State 9:
|
66
|
+
ww.w
|
67
|
+
xbxb
|
68
|
+
..bw
|
69
|
+
x.xb
|
70
|
+
w: 3,2 -> 2,0
|
71
|
+
|
72
|
+
State 10:
|
73
|
+
wwww
|
74
|
+
xbxb
|
75
|
+
..b.
|
76
|
+
x.xb
|
77
|
+
b: 1,1 -> 3,2
|
78
|
+
|
79
|
+
State 11:
|
80
|
+
wwww
|
81
|
+
x.xb
|
82
|
+
..bb
|
83
|
+
x.xb
|
84
|
+
w: 3,0 -> 1,1
|
85
|
+
|
86
|
+
State 12:
|
87
|
+
www.
|
88
|
+
xwxb
|
89
|
+
..bb
|
90
|
+
x.xb
|
@@ -0,0 +1,90 @@
|
|
1
|
+
Solved
|
2
|
+
State 0:
|
3
|
+
bbb.
|
4
|
+
xbxw
|
5
|
+
..ww
|
6
|
+
x.xw
|
7
|
+
w: 2,2 -> 3,0
|
8
|
+
|
9
|
+
State 1:
|
10
|
+
bbbw
|
11
|
+
xbxw
|
12
|
+
...w
|
13
|
+
x.xw
|
14
|
+
b: 1,0 -> 2,2
|
15
|
+
|
16
|
+
State 2:
|
17
|
+
b.bw
|
18
|
+
xbxw
|
19
|
+
..bw
|
20
|
+
x.xw
|
21
|
+
b: 0,0 -> 1,2
|
22
|
+
|
23
|
+
State 3:
|
24
|
+
..bw
|
25
|
+
xbxw
|
26
|
+
.bbw
|
27
|
+
x.xw
|
28
|
+
w: 3,1 -> 1,0
|
29
|
+
|
30
|
+
State 4:
|
31
|
+
.wbw
|
32
|
+
xbx.
|
33
|
+
.bbw
|
34
|
+
x.xw
|
35
|
+
b: 1,2 -> 3,1
|
36
|
+
|
37
|
+
State 5:
|
38
|
+
.wbw
|
39
|
+
xbxb
|
40
|
+
..bw
|
41
|
+
x.xw
|
42
|
+
w: 3,3 -> 1,2
|
43
|
+
|
44
|
+
State 6:
|
45
|
+
.wbw
|
46
|
+
xbxb
|
47
|
+
.wbw
|
48
|
+
x.x.
|
49
|
+
w: 1,2 -> 0,0
|
50
|
+
|
51
|
+
State 7:
|
52
|
+
wwbw
|
53
|
+
xbxb
|
54
|
+
..bw
|
55
|
+
x.x.
|
56
|
+
b: 2,0 -> 1,2
|
57
|
+
|
58
|
+
State 8:
|
59
|
+
ww.w
|
60
|
+
xbxb
|
61
|
+
.bbw
|
62
|
+
x.x.
|
63
|
+
b: 1,2 -> 3,3
|
64
|
+
|
65
|
+
State 9:
|
66
|
+
ww.w
|
67
|
+
xbxb
|
68
|
+
..bw
|
69
|
+
x.xb
|
70
|
+
w: 3,2 -> 2,0
|
71
|
+
|
72
|
+
State 10:
|
73
|
+
wwww
|
74
|
+
xbxb
|
75
|
+
..b.
|
76
|
+
x.xb
|
77
|
+
b: 1,1 -> 3,2
|
78
|
+
|
79
|
+
State 11:
|
80
|
+
wwww
|
81
|
+
x.xb
|
82
|
+
..bb
|
83
|
+
x.xb
|
84
|
+
w: 3,0 -> 1,1
|
85
|
+
|
86
|
+
State 12:
|
87
|
+
www.
|
88
|
+
xwxb
|
89
|
+
..bb
|
90
|
+
x.xb
|
@@ -0,0 +1,90 @@
|
|
1
|
+
Solved
|
2
|
+
State 0:
|
3
|
+
bbb.
|
4
|
+
xbxw
|
5
|
+
..ww
|
6
|
+
x.xw
|
7
|
+
w: 3,3 -> 1,2
|
8
|
+
|
9
|
+
State 1:
|
10
|
+
bbb.
|
11
|
+
xbxw
|
12
|
+
.www
|
13
|
+
x.x.
|
14
|
+
b: 1,1 -> 3,0
|
15
|
+
|
16
|
+
State 2:
|
17
|
+
bbbb
|
18
|
+
x.xw
|
19
|
+
.www
|
20
|
+
x.x.
|
21
|
+
w: 3,2 -> 1,1
|
22
|
+
|
23
|
+
State 3:
|
24
|
+
bbbb
|
25
|
+
xwxw
|
26
|
+
.ww.
|
27
|
+
x.x.
|
28
|
+
b: 2,0 -> 3,2
|
29
|
+
|
30
|
+
State 4:
|
31
|
+
bb.b
|
32
|
+
xwxw
|
33
|
+
.wwb
|
34
|
+
x.x.
|
35
|
+
w: 1,2 -> 2,0
|
36
|
+
|
37
|
+
State 5:
|
38
|
+
bbwb
|
39
|
+
xwxw
|
40
|
+
..wb
|
41
|
+
x.x.
|
42
|
+
b: 0,0 -> 1,2
|
43
|
+
|
44
|
+
State 6:
|
45
|
+
.bwb
|
46
|
+
xwxw
|
47
|
+
.bwb
|
48
|
+
x.x.
|
49
|
+
b: 1,2 -> 3,3
|
50
|
+
|
51
|
+
State 7:
|
52
|
+
.bwb
|
53
|
+
xwxw
|
54
|
+
..wb
|
55
|
+
x.xb
|
56
|
+
w: 3,1 -> 1,2
|
57
|
+
|
58
|
+
State 8:
|
59
|
+
.bwb
|
60
|
+
xwx.
|
61
|
+
.wwb
|
62
|
+
x.xb
|
63
|
+
b: 1,0 -> 3,1
|
64
|
+
|
65
|
+
State 9:
|
66
|
+
..wb
|
67
|
+
xwxb
|
68
|
+
.wwb
|
69
|
+
x.xb
|
70
|
+
w: 2,2 -> 1,0
|
71
|
+
|
72
|
+
State 10:
|
73
|
+
.wwb
|
74
|
+
xwxb
|
75
|
+
.w.b
|
76
|
+
x.xb
|
77
|
+
b: 3,0 -> 2,2
|
78
|
+
|
79
|
+
State 11:
|
80
|
+
.ww.
|
81
|
+
xwxb
|
82
|
+
.wbb
|
83
|
+
x.xb
|
84
|
+
w: 1,2 -> 0,0
|
85
|
+
|
86
|
+
State 12:
|
87
|
+
www.
|
88
|
+
xwxb
|
89
|
+
..bb
|
90
|
+
x.xb
|
@@ -1,23 +1,5 @@
|
|
1
1
|
describe "Futoshiki" do
|
2
2
|
it do
|
3
|
-
expect("futoshiki").to
|
4
|
-
2 5 3 4 1 7 6<9 8
|
5
|
-
|
6
|
-
1 9 7 2 8 5 3<4<6
|
7
|
-
_
|
8
|
-
7<8 2 5>3>1 4<6 9
|
9
|
-
^
|
10
|
-
8 1<5<9 7 6 2 3 4
|
11
|
-
^
|
12
|
-
4 7>6>1 9 2 5 8 3
|
13
|
-
^ ^ ^
|
14
|
-
6 4 1 8 2 3 9 5 7
|
15
|
-
_ _ ^ _ _
|
16
|
-
9 3 4 6>5 8 7 1 2
|
17
|
-
_
|
18
|
-
5 2 9>3 6>4 8>7 1
|
19
|
-
_
|
20
|
-
3 6 8>7>4 9 1<2 5
|
21
|
-
EOF
|
3
|
+
expect("futoshiki").to have_output_matching_saved_example
|
22
4
|
end
|
23
5
|
end
|
@@ -1,98 +1,5 @@
|
|
1
|
-
# There are multiple solutions, so this test is nondeterministic
|
2
|
-
# This is what Z3 4.8.13 returns
|
3
1
|
describe "Knights Swap Puzzle" do
|
4
2
|
it do
|
5
|
-
expect("knights_puzzle").to
|
6
|
-
Solved
|
7
|
-
State 0:
|
8
|
-
bbb.
|
9
|
-
xbxw
|
10
|
-
..ww
|
11
|
-
x.xw
|
12
|
-
w: 2,2 -> 3,0
|
13
|
-
|
14
|
-
State 1:
|
15
|
-
bbbw
|
16
|
-
xbxw
|
17
|
-
...w
|
18
|
-
x.xw
|
19
|
-
b: 1,0 -> 2,2
|
20
|
-
|
21
|
-
State 2:
|
22
|
-
b.bw
|
23
|
-
xbxw
|
24
|
-
..bw
|
25
|
-
x.xw
|
26
|
-
w: 3,1 -> 1,0
|
27
|
-
|
28
|
-
State 3:
|
29
|
-
bwbw
|
30
|
-
xbx.
|
31
|
-
..bw
|
32
|
-
x.xw
|
33
|
-
b: 0,0 -> 1,2
|
34
|
-
|
35
|
-
State 4:
|
36
|
-
.wbw
|
37
|
-
xbx.
|
38
|
-
.bbw
|
39
|
-
x.xw
|
40
|
-
b: 1,2 -> 3,1
|
41
|
-
|
42
|
-
State 5:
|
43
|
-
.wbw
|
44
|
-
xbxb
|
45
|
-
..bw
|
46
|
-
x.xw
|
47
|
-
w: 3,3 -> 1,2
|
48
|
-
|
49
|
-
State 6:
|
50
|
-
.wbw
|
51
|
-
xbxb
|
52
|
-
.wbw
|
53
|
-
x.x.
|
54
|
-
w: 1,2 -> 0,0
|
55
|
-
|
56
|
-
State 7:
|
57
|
-
wwbw
|
58
|
-
xbxb
|
59
|
-
..bw
|
60
|
-
x.x.
|
61
|
-
b: 2,0 -> 1,2
|
62
|
-
|
63
|
-
State 8:
|
64
|
-
ww.w
|
65
|
-
xbxb
|
66
|
-
.bbw
|
67
|
-
x.x.
|
68
|
-
w: 3,2 -> 2,0
|
69
|
-
|
70
|
-
State 9:
|
71
|
-
wwww
|
72
|
-
xbxb
|
73
|
-
.bb.
|
74
|
-
x.x.
|
75
|
-
b: 1,1 -> 3,2
|
76
|
-
|
77
|
-
State 10:
|
78
|
-
wwww
|
79
|
-
x.xb
|
80
|
-
.bbb
|
81
|
-
x.x.
|
82
|
-
b: 1,2 -> 3,3
|
83
|
-
|
84
|
-
State 11:
|
85
|
-
wwww
|
86
|
-
x.xb
|
87
|
-
..bb
|
88
|
-
x.xb
|
89
|
-
w: 3,0 -> 1,1
|
90
|
-
|
91
|
-
State 12:
|
92
|
-
www.
|
93
|
-
xwxb
|
94
|
-
..bb
|
95
|
-
x.xb
|
96
|
-
EOF
|
3
|
+
expect("knights_puzzle").to have_output_matching_saved_example
|
97
4
|
end
|
98
5
|
end
|
data/spec/optimize_spec.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# Disabled as it crashes on Z3 4.8.13
|
4
4
|
module Z3
|
5
|
-
|
5
|
+
describe Optimize do
|
6
6
|
let(:optimize) { Optimize.new }
|
7
7
|
let(:a) { Z3.Int("a") }
|
8
8
|
let(:b) { Z3.Int("b") }
|
@@ -34,6 +34,15 @@ module Z3
|
|
34
34
|
])
|
35
35
|
end
|
36
36
|
|
37
|
+
it "#assert_soft" do
|
38
|
+
optimize.assert_soft a > 0
|
39
|
+
optimize.assert_soft a < 0
|
40
|
+
optimize.assert_soft a < 10
|
41
|
+
optimize.maximize a
|
42
|
+
expect(optimize).to be_satisfiable
|
43
|
+
expect(optimize.model[a].to_i).to eq 9
|
44
|
+
end
|
45
|
+
|
37
46
|
it "#statistics" do
|
38
47
|
optimize.assert a + b == 4
|
39
48
|
optimize.assert b >= 2
|
@@ -42,16 +51,6 @@ module Z3
|
|
42
51
|
expect(stats.keys).to match_array(["rlimit count", "max memory", "memory", "num allocs"])
|
43
52
|
end
|
44
53
|
|
45
|
-
# This is a very simple example of unknown satisfiablity
|
46
|
-
# so we might need more complex one in the future
|
47
|
-
# Unlike Z3::Solver, this is unknown even 4.6.0
|
48
|
-
it "unknown satisfiability" do
|
49
|
-
optimize.assert a**3 == a
|
50
|
-
expect(optimize.check).to eq(:unknown)
|
51
|
-
expect{optimize.satisfiable?}.to raise_error("Satisfiability unknown")
|
52
|
-
expect{optimize.unsatisfiable?}.to raise_error("Satisfiability unknown")
|
53
|
-
end
|
54
|
-
|
55
54
|
it "unknown satisfiability" do
|
56
55
|
optimize.assert a**a == a
|
57
56
|
expect(optimize.check).to eq(:unknown)
|
data/spec/set_expr_spec.rb
CHANGED
data/spec/solver_spec.rb
CHANGED
@@ -43,7 +43,7 @@ module Z3
|
|
43
43
|
# This is a very simple example of unknown satisfiablity
|
44
44
|
# so we might need more complex one in the future
|
45
45
|
# This is now satisfiable in 4.6.0
|
46
|
-
if Z3.
|
46
|
+
if Z3.version_at_least?(4, 6)
|
47
47
|
it "unknown satisfiability (until 4.6 fix)" do
|
48
48
|
solver.assert a**3 == a
|
49
49
|
expect(solver.check).to eq(:sat)
|
data/spec/spec_helper.rb
CHANGED
@@ -38,6 +38,20 @@ RSpec::Matchers.define :have_output do |expected|
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
RSpec::Matchers.define :have_output_matching_saved_example do
|
42
|
+
match do |file_name|
|
43
|
+
executable_path = "#{__dir__}/../examples/#{file_name}"
|
44
|
+
actual = IO.popen("ruby -r./spec/coverage_helper #{executable_path}").read
|
45
|
+
@actual = actual.gsub(/ *$/, "")
|
46
|
+
@expected = Pathname("spec/integration/examples").glob("#{file_name}-*.txt").map(&:read).map{|o| o.gsub(/ *$/, "")}
|
47
|
+
@expected.include?(@actual)
|
48
|
+
end
|
49
|
+
|
50
|
+
failure_message do |actual|
|
51
|
+
"Expected one of saved examples, but got:\n#{@actual}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
41
55
|
RSpec::Matchers.define :have_output_no_color do |expected|
|
42
56
|
match do |file_name|
|
43
57
|
executable_path = "#{__dir__}/../examples/#{file_name}"
|
data/spec/z3_spec.rb
CHANGED
@@ -2,4 +2,14 @@ describe Z3 do
|
|
2
2
|
it "#version return version number of Z3 library" do
|
3
3
|
expect(Z3.version).to match(/\A\d+\.\d+\.\d+\.\d+\z/)
|
4
4
|
end
|
5
|
+
|
6
|
+
it "#version_at_least return if version matches" do
|
7
|
+
version = Z3.version.split(".").map(&:to_i)
|
8
|
+
expect(Z3.version_at_least?(*version)).to eq(true)
|
9
|
+
expect(Z3.version_at_least?(*version[0,2])).to eq(true)
|
10
|
+
expect(Z3.version_at_least?(*version[0,1])).to eq(true)
|
11
|
+
expect(Z3.version_at_least?(version[0])).to eq(true)
|
12
|
+
expect(Z3.version_at_least?(*version[0,2], 999)).to eq(false)
|
13
|
+
expect(Z3.version_at_least?(999)).to eq(false)
|
14
|
+
end
|
5
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: z3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20221020
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomasz Wegrzanowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -280,6 +280,14 @@ files:
|
|
280
280
|
- spec/integration/dominion_spec.rb
|
281
281
|
- spec/integration/dominosa_spec.rb
|
282
282
|
- spec/integration/eulero_spec.rb
|
283
|
+
- spec/integration/examples/abc_path-1.txt
|
284
|
+
- spec/integration/examples/abc_path-2.txt
|
285
|
+
- spec/integration/examples/futoshiki-1.txt
|
286
|
+
- spec/integration/examples/futoshiki-2.txt
|
287
|
+
- spec/integration/examples/knights_puzzle-1.txt
|
288
|
+
- spec/integration/examples/knights_puzzle-2.txt
|
289
|
+
- spec/integration/examples/knights_puzzle-3.txt
|
290
|
+
- spec/integration/examples/knights_puzzle-4.txt
|
283
291
|
- spec/integration/four_hackers_puzzle_spec.rb
|
284
292
|
- spec/integration/futoshiki_spec.rb
|
285
293
|
- spec/integration/geometry_problem_spec.rb
|