Skip to content

Commit a794771

Browse files
committed
update template
1 parent 588b20d commit a794771

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

copypasta/template/interactive_problem/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ func (io io) readInitData() (d initData) {
3030
return
3131
}
3232

33-
func (io io) query(req request) (resp response) {
34-
Fprintln(io.out, "?", req.i)
33+
func (io io) query(q request) (resp response) {
34+
Fprintln(io.out, "?", q.i)
3535
io.out.Flush()
3636
Fscan(io.in, &resp.v)
3737
if resp.v < 0 {
@@ -41,9 +41,10 @@ func (io io) query(req request) (resp response) {
4141
}
4242

4343
func (io io) printAnswer(a answer) {
44-
Fprint(io.out, "! ")
44+
Fprint(io.out, "!")
45+
//Fprint(io.out, " ", len(a.ans))
4546
for _, v := range a.ans {
46-
Fprint(io.out, v, " ")
47+
Fprint(io.out, " ", v)
4748
}
4849
Fprintln(io.out)
4950
io.out.Flush()

copypasta/template/interactive_problem/main_test.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ var failedCount int
1818
type mockIO struct {
1919
initData
2020
answer
21-
innerData []int
21+
hiddenData []int //
2222

2323
_t *testing.T
2424
caseNum int
2525
queryLimit int
2626
queryCnt int
2727
}
2828

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)
3333
}
3434

3535
// Mock initData
@@ -40,9 +40,9 @@ func (io *mockIO) readInitData() (d initData) {
4040
// Check answer
4141
func (io *mockIO) printAnswer(actualAns answer) {
4242
expectedAns := io.answer
43-
if !assert.EqualValues(io._t, expectedAns, actualAns, "Wrong Answer %d\nInner Data:\n%v", io.caseNum, io) {
43+
if !assert.EqualValues(io._t, expectedAns, actualAns, "Wrong Answer %d\nCase Data:\n%v", io.caseNum, io) {
4444
if failedCount++; failedCount > failedCountLimit {
45-
io._t.Fatal("too many wrong answers, terminated")
45+
io._t.Fatal("too many failed cases, terminated")
4646
}
4747
}
4848

@@ -51,24 +51,24 @@ func (io *mockIO) printAnswer(actualAns answer) {
5151

5252
return true
5353
}
54-
if !assert.Truef(io._t, ansChecker(), "Wrong Answer %d\nMy Answer:\n%v\nInner Data:\n%v", io.caseNum, actualAns, io) {
54+
if !assert.Truef(io._t, ansChecker(), "Wrong Answer %d\nMy Answer:\n%v\nCase Data:\n%v", io.caseNum, actualAns, io) {
5555
if failedCount++; failedCount > failedCountLimit {
56-
io._t.Fatal("too many wrong answers, terminated")
56+
io._t.Fatal("too many failed cases, terminated")
5757
}
5858
}
5959
}
6060

6161
// Mock query
62-
func (io *mockIO) query(req request) (resp response) {
62+
func (io *mockIO) query(q request) (resp response) {
6363
if io.caseNum == debugCaseNum {
64-
Print("Query ", req, " ")
64+
Print("Query ", q, " ")
6565
defer func() { Println(resp) }()
6666
}
67-
if io.queryCnt++; io.queryCnt > io.queryLimit {
68-
io._t.Fatalf("Query Limit Exceeded %d\nInner Data:\n%v", io.caseNum, io)
69-
}
7067

68+
io.queryCnt++
69+
//if io.queryCnt > io.queryLimit { io._t.Fatalf("Query Limit Exceeded %d\nCase Data:\n%v", io.caseNum, io) }
7170

71+
// calc q ...
7272

7373
return
7474
}
@@ -81,17 +81,27 @@ func Test_doInteraction(_t *testing.T) {
8181
}
8282
io := &mockIO{_t: _t, caseNum: tc}
8383

84+
// gen random data ...
8485
rg = testutil.NewRandGenerator()
8586
n := rg.Int(2, 4)
8687
a := rg.IntSlice(n, 1, n)
8788

8889
io.n = n
8990
io.ans = a
90-
io.innerData = a
91+
io.hiddenData = a
9192

93+
// set limit ...
9294
io.queryLimit = n + 30
9395

9496
doInteraction(io)
97+
98+
if io.queryCnt > io.queryLimit {
99+
io._t.Errorf("Query Limit Exceeded %d\n%d > %d\nCase 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+
95105
if tc == checkTC {
96106
_t.Logf("%d cases checked.", tc)
97107
checkTC <<= 1

0 commit comments

Comments
 (0)