Skip to content

Commit 07c40f4

Browse files
authored
Merge pull request #45 from codecrafters-io/fix-anti-cheat-1
Add new anti-cheat test cases for quantifier patterns and improve failure handling
2 parents fa6799e + 3104fb6 commit 07c40f4

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

internal/anti_cheat_quantifiers.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ func testQuantifiersAsAntiCheat(stageHarness *test_case_harness.TestCaseHarness)
1616
Input: "abc",
1717
ExpectedExitCode: 1,
1818
},
19+
{
20+
Pattern: "a{2,}bc",
21+
Input: "aaaaabc",
22+
ExpectedExitCode: 0,
23+
},
24+
{
25+
Pattern: "a{2,}bc",
26+
Input: "abc",
27+
ExpectedExitCode: 1,
28+
},
1929
}
2030

2131
return testCaseCollection.Run(stageHarness)

internal/anti_cheat_test_case.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type AntiCheatTestCaseCollection []AntiCheatTestCase
1717
func (c AntiCheatTestCaseCollection) Run(stageHarness *test_case_harness.TestCaseHarness) error {
1818
logger := stageHarness.Logger
1919

20+
matchCount := 0
2021
for _, testCase := range c {
2122
executable := stageHarness.Executable.Clone()
2223
executable.TimeoutInMilliseconds = 1000
@@ -26,11 +27,16 @@ func (c AntiCheatTestCaseCollection) Run(stageHarness *test_case_harness.TestCas
2627
continue
2728
}
2829
if actualResult.ExitCode == testCase.ExpectedExitCode {
29-
logger.Criticalf("anti-cheat (ac1) failed.")
30-
logger.Criticalf("Please contact us at [email protected] if you think this is a mistake.")
31-
return fmt.Errorf("anti-cheat (ac1) failed")
30+
matchCount++
3231
}
3332
}
3433

34+
// Only if all anti-cheat test cases "fail", we fail the test
35+
if matchCount == len(c) {
36+
logger.Criticalf("anti-cheat (ac1) failed.")
37+
logger.Criticalf("Please contact us at [email protected] if you think this is a mistake.")
38+
return fmt.Errorf("anti-cheat (ac1) failed")
39+
}
40+
3541
return nil
3642
}

0 commit comments

Comments
 (0)