This repository was archived by the owner on Dec 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsolver_trail_test.go
107 lines (91 loc) · 1.44 KB
/
solver_trail_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
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
package sat
import (
"fmt"
"reflect"
"testing"
"github.com/mitchellh/go-sat/cnf"
)
func TestSolverValueLit(t *testing.T) {
cases := []struct {
Assert int
Lit int
Result tribool
}{
{
4,
-4,
triFalse,
},
{
4,
4,
triTrue,
},
{
-4,
4,
triFalse,
},
{
-4,
-4,
triTrue,
},
}
for i, tc := range cases {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
s := New()
s.assertLiteral(cnf.NewLitInt(tc.Assert), nil)
l := cnf.NewLitInt(tc.Lit)
result := s.valueLit(l)
if result != tc.Result {
t.Fatalf("bad: %T", result)
}
})
}
}
func TestSolverTrimToDecisionLevel(t *testing.T) {
cases := []struct {
Assert []int // negative will be decision
Level int
Result []int
}{
{
[]int{-1, -2, 3},
2,
[]int{-1, -2, 3},
},
{
[]int{-1, -2, 3},
1,
[]int{-1},
},
{
[]int{-1, -2, 3, -4, 5},
2,
[]int{-1, -2, 3},
},
}
for i, tc := range cases {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
s := New()
for _, l := range tc.Assert {
if l < 0 {
s.newDecisionLevel()
}
s.assertLiteral(cnf.NewLitInt(l), nil)
}
s.trimToDecisionLevel(tc.Level)
var result []int
for _, l := range s.trail {
result = append(result, l.Int())
}
if !reflect.DeepEqual(result, tc.Result) {
t.Fatalf("bad: %#v", result)
}
if s.decisionLevel() != tc.Level {
t.Fatalf("bad: %d", s.decisionLevel())
}
})
}
}