@@ -18,18 +18,18 @@ var failedCount int
18
18
type mockIO struct {
19
19
initData
20
20
answer
21
- innerData []int
21
+ hiddenData []int //
22
22
23
23
_t * testing.T
24
24
caseNum int
25
25
queryLimit int
26
26
queryCnt int
27
27
}
28
28
29
- func (io * mockIO ) String () ( s string ) {
30
- s = Sprintf ("%v" , io .innerData )
31
- //s = strings.Join(io.innerData , "\n")
32
- return
29
+ func (io * mockIO ) String () string {
30
+ hStr : = Sprintf ("%v" , io .hiddenData )
31
+ //hStr : = strings.Join(io.hiddenData , "\n")
32
+ return Sprintf ( "%+v \n %s" , io . initData , hStr )
33
33
}
34
34
35
35
// Mock initData
@@ -40,9 +40,9 @@ func (io *mockIO) readInitData() (d initData) {
40
40
// Check answer
41
41
func (io * mockIO ) printAnswer (actualAns answer ) {
42
42
expectedAns := io .answer
43
- if ! assert .EqualValues (io ._t , expectedAns , actualAns , "Wrong Answer %d\n Inner Data:\n %v" , io .caseNum , io ) {
43
+ if ! assert .EqualValues (io ._t , expectedAns , actualAns , "Wrong Answer %d\n Case Data:\n %v" , io .caseNum , io ) {
44
44
if failedCount ++ ; failedCount > failedCountLimit {
45
- io ._t .Fatal ("too many wrong answers , terminated" )
45
+ io ._t .Fatal ("too many failed cases , terminated" )
46
46
}
47
47
}
48
48
@@ -51,24 +51,24 @@ func (io *mockIO) printAnswer(actualAns answer) {
51
51
52
52
return true
53
53
}
54
- if ! assert .Truef (io ._t , ansChecker (), "Wrong Answer %d\n My Answer:\n %v\n Inner Data:\n %v" , io .caseNum , actualAns , io ) {
54
+ if ! assert .Truef (io ._t , ansChecker (), "Wrong Answer %d\n My Answer:\n %v\n Case Data:\n %v" , io .caseNum , actualAns , io ) {
55
55
if failedCount ++ ; failedCount > failedCountLimit {
56
- io ._t .Fatal ("too many wrong answers , terminated" )
56
+ io ._t .Fatal ("too many failed cases , terminated" )
57
57
}
58
58
}
59
59
}
60
60
61
61
// Mock query
62
- func (io * mockIO ) query (req request ) (resp response ) {
62
+ func (io * mockIO ) query (q request ) (resp response ) {
63
63
if io .caseNum == debugCaseNum {
64
- Print ("Query " , req , " " )
64
+ Print ("Query " , q , " " )
65
65
defer func () { Println (resp ) }()
66
66
}
67
- if io .queryCnt ++ ; io .queryCnt > io .queryLimit {
68
- io ._t .Fatalf ("Query Limit Exceeded %d\n Inner Data:\n %v" , io .caseNum , io )
69
- }
70
67
68
+ io .queryCnt ++
69
+ //if io.queryCnt > io.queryLimit { io._t.Fatalf("Query Limit Exceeded %d\nCase Data:\n%v", io.caseNum, io) }
71
70
71
+ // calc q ...
72
72
73
73
return
74
74
}
@@ -81,17 +81,27 @@ func Test_doInteraction(_t *testing.T) {
81
81
}
82
82
io := & mockIO {_t : _t , caseNum : tc }
83
83
84
+ // gen random data ...
84
85
rg = testutil .NewRandGenerator ()
85
86
n := rg .Int (2 , 4 )
86
87
a := rg .IntSlice (n , 1 , n )
87
88
88
89
io .n = n
89
90
io .ans = a
90
- io .innerData = a
91
+ io .hiddenData = a
91
92
93
+ // set limit ...
92
94
io .queryLimit = n + 30
93
95
94
96
doInteraction (io )
97
+
98
+ if io .queryCnt > io .queryLimit {
99
+ io ._t .Errorf ("Query Limit Exceeded %d\n %d > %d\n Case Data:\n %v" , io .caseNum , io .queryCnt , io .queryLimit , io )
100
+ if failedCount ++ ; failedCount > failedCountLimit {
101
+ io ._t .Fatal ("too many failed cases, terminated" )
102
+ }
103
+ }
104
+
95
105
if tc == checkTC {
96
106
_t .Logf ("%d cases checked." , tc )
97
107
checkTC <<= 1
0 commit comments