Skip to content

Commit

Permalink
Merge pull request #1070 from yosupo06/feature/allow_re
Browse files Browse the repository at this point in the history
add allow_re
  • Loading branch information
yosupo06 authored Dec 16, 2023
2 parents 1a973db + 22d26c1 commit f54fda2
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 7 deletions.
7 changes: 7 additions & 0 deletions generate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ def test_call_from_outside(self):
chdir(str(cwd))


class TestAllowRE(unittest.TestCase):
def test_allow_re(self):
with create_test_dir('allow_re') as test_dir:
proc = run(
['./generate.py', str(Path(test_dir) / 'allow_re/info.toml'), '--test'])
self.assertEqual(proc.returncode, 0)

class TestAllowTLE(unittest.TestCase):
def test_allow_tle(self):
with create_test_dir('allow_tle') as test_dir:
Expand Down
19 changes: 12 additions & 7 deletions problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,17 +395,22 @@ def judge(self, src: Path, config: dict):
logging_result(result, start, end,
'{} : {}'.format(case, checker_output.decode('utf-8')))

allow_status = set()
allow_status.add('AC')
if config.get('wrong', False):
allow_status.update(['WA', 'RE', 'TLE'])
if config.get('allow_tle', False):
allow_status.add('TLE')
if config.get('allow_re', False):
allow_status.add('RE')

if len(results - allow_status) != 0:
logger.error('unexpected status was appeared: {} (allowed {})'.format(results, allow_status))

if config.get('wrong', False):
if results == {'AC'}:
logger.error('wrong solution got accept: {}'.format(src))
exit(1)
else:
if 'WA' in results or 'RE' in results:
logger.error('correct solution got wa/re: {}'.format(src))
exit(1)
if not config.get('allow_tle', False) and 'TLE' in results:
logger.error('fast solution got tle: {}'.format(src))
exit(1)

def calc_hashes(self) -> MutableMapping[str, str]:
hashes: MutableMapping[str, str] = dict()
Expand Down
62 changes: 62 additions & 0 deletions test/allow_re/checker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// https://github.com/MikeMirzayanov/testlib/blob/master/checkers/wcmp.cpp

// The MIT License (MIT)

// Copyright (c) 2015 Mike Mirzayanov

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "testlib.h"

using namespace std;

int main(int argc, char * argv[])
{
setName("compare sequences of tokens");
registerTestlibCmd(argc, argv);

int n = 0;
string j, p;

while (!ans.seekEof() && !ouf.seekEof())
{
n++;

ans.readWordTo(j);
ouf.readWordTo(p);

if (j != p)
quitf(_wa, "%d%s words differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(), compress(j).c_str(), compress(p).c_str());
}

if (ans.seekEof() && ouf.seekEof())
{
if (n == 1)
quitf(_ok, "\"%s\"", compress(j).c_str());
else
quitf(_ok, "%d tokens", n);
}
else
{
if (ans.seekEof())
quitf(_wa, "Participant output contains extra tokens");
else
quitf(_wa, "Unexpected EOF in the participants output");
}
}
1 change: 1 addition & 0 deletions test/allow_re/gen/example_00.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1234 5678
1 change: 1 addition & 0 deletions test/allow_re/gen/example_01.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1000000000 1000000000
6 changes: 6 additions & 0 deletions test/allow_re/hash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"example_00.in": "346a847f5875beb74d494de0680a81fc2ff840b12f79de30dc7ef3a798d23c28",
"example_00.out": "d6e0da7b83d84fac4d6a6bd11ad0b0e6ea72351748b4f6a277b9762d9d0eb159",
"example_01.in": "0073cf03577a737756752129cc3abcb9f5a4069c705321ee2115574cc31c59f9",
"example_01.out": "6f2264250160ee91b20af64f30128e3787fcf641f1c504f7ac752597e7d2cc09"
}
10 changes: 10 additions & 0 deletions test/allow_re/info.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title = 'Simple AplusB'
timelimit = 2.0

[[tests]]
name = "example.in"
number = 2

[[solutions]]
name = "naive.cpp"
allow_re = true
18 changes: 18 additions & 0 deletions test/allow_re/sol/correct.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <iostream>
#include <vector>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

int main() {

int a, b;
scanf("%d %d", &a, &b);
printf("%d\n", a + b);
return 0;
}
19 changes: 19 additions & 0 deletions test/allow_re/sol/naive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
#include <vector>
#include <cassert>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

int main() {
int a, b;
scanf("%d %d", &a, &b);
assert(a <= 1000 && b <= 1000);
printf("%d\n", a + b);
return 0;
}
25 changes: 25 additions & 0 deletions test/allow_re/task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## @{keyword.statement}
整数 $a, b$ が与えられます。 $a + b$ を出力してください。

## @{keyword.constraints}

- $0 \leq a, b \leq 10^9$


## @{keyword.input}

```
$A$ $B$
```

## @{keyword.output}

```
$A + B$
```

## @{keyword.sample}

@{example.example_00}

@{example.example_01}
12 changes: 12 additions & 0 deletions test/allow_re/verifier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "testlib.h"

int main() {
registerValidation();

inf.readInt(0, 1'000'000'000); // a
inf.readSpace();
inf.readInt(0, 1'000'000'000); // b
inf.readChar('\n');
inf.readEof();
return 0;
}

0 comments on commit f54fda2

Please sign in to comment.