check_test.go
2.0 KB
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
package protocol
import (
"encoding/json"
"fmt"
"testing"
)
func TestSelfChecks(t *testing.T) {
nsc := func(id, pid int64, checkItem, answer string) SelfCheck {
item := SelfCheck{
CheckItem: checkItem, Answer: answer, Id: id, ParentId: pid,
}
item.GroupId = pid
if pid == 0 {
item.GroupId = id
}
return item
}
nscNo := func(id, pid int64, checkItem, answer, reason string) SelfCheck {
item := nsc(id, pid, checkItem, answer)
item.Reason = reason
return item
}
input := SelfChecks([]SelfCheck{
nsc(1, 0, "1", ""),
nsc(2, 1, "2", OptionYes),
nsc(3, 1, "3", OptionNo),
nsc(4, 1, "4", OptionUncertain),
nsc(5, 1, "5", ""),
nsc(6, 0, "6", ""),
nsc(7, 6, "7", OptionUncertain),
nscNo(8, 6, "8", OptionNo, " "),
nsc(9, 6, "9", OptionUncertain),
nsc(10, 6, "10", ""),
nsc(11, 0, "11", OptionYes),
nsc(12, 0, "12", OptionYes),
})
input.SetSelfChecksLevel1ByRule()
if input[0].Answer != OptionYes || input[5].Answer != OptionNo {
t.Fatal(fmt.Sprintf("SetSelfChecksLevel1ByRule Fail"))
}
if input.Static()[0].Total != 3 || input.Static()[0].Item != OptionYes {
t.Fatal(fmt.Sprintf("Static Fail"))
}
if input[7].Reason != " " {
t.Fatal("reason data error")
}
input.Format()
if input[7].Reason == " " {
t.Fatal("reason data error")
}
t.Log(input.String())
inputCompare := SelfChecks([]SelfCheck{
nsc(1, 0, "1", ""),
nsc(2, 1, "2", OptionYes),
nsc(3, 1, "3", OptionNo),
nsc(4, 1, "4", OptionNo), //diff
nsc(5, 1, "5", ""),
nsc(6, 0, "6", ""),
nsc(7, 6, "7", OptionUncertain),
nscNo(8, 6, "8", OptionNo, " "),
nsc(9, 6, "9", OptionUncertain),
nsc(10, 6, "10", ""),
nsc(11, 0, "11", OptionYes),
nsc(12, 0, "12", OptionNo), //diff
})
inputCompare.SetSelfChecksLevel1ByRule()
inputCompare.Format()
data, err := json.Marshal(input)
if err != nil {
t.Fatal(err)
}
o, err := inputCompare.Compare(string(data))
if err != nil {
t.Fatal(err)
}
if len(o) != 2 {
t.Fatal("Compare fail")
}
t.Log("Compare:", o.String())
}
func TestSiftingResults(t *testing.T) {
}