forked from mitchellh/go-z3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolver_test.go
66 lines (51 loc) · 1.14 KB
/
solver_test.go
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
package z3
import (
"testing"
)
func TestSolver(t *testing.T) {
config := NewConfig()
defer config.Close()
ctx := NewContext(config)
defer ctx.Close()
// Create the "x xor y" constraint
boolTyp := ctx.BoolSort()
x := ctx.Const(ctx.Symbol("x"), boolTyp)
y := ctx.Const(ctx.Symbol("y"), boolTyp)
x_xor_y := x.Xor(y)
ast := x_xor_y
t.Logf("\nAST:\n%s", ast.String())
// Create the solver
s := ctx.NewSolver()
defer s.Close()
// Assert constraints
s.Assert(x_xor_y)
// Solve
result := s.Check()
if result != True {
t.Fatalf("bad: %v", result)
}
// Get the model
m := s.Model()
defer m.Close()
t.Logf("\nModel:\n%s", m.String())
}
func TestRealSolver(t *testing.T) {
config := NewConfig()
defer config.Close()
ctx := NewContext(config)
defer ctx.Close()
x := ctx.Const(ctx.Symbol("x"), ctx.RealSort())
y := ctx.Const(ctx.Symbol("y"), ctx.RealSort())
ast := x.Div(y).Eq(ctx.Real(1, 1, ctx.RealSort()))
t.Logf("\nAST:\n%s", ast.String())
// Create the solver
s := ctx.NewSolver()
defer s.Close()
// Assert constraints
s.Assert(ast)
// Solve
result := s.Check()
if result != True {
t.Fatalf("bad: %v", result)
}
}