Skip to content

Commit ee22aa9

Browse files
authored
Merge pull request #351 from Matistjati/deterministic-input-fuzzing-2
More deterministic input fuzzing
2 parents 5e43d6a + 6371f43 commit ee22aa9

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

problemtools/verifyproblem.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
from typing import Any, Callable, ClassVar, Literal, Pattern, Match, ParamSpec, TypeVar
4141
from pydantic import ValidationError
4242

43+
random.seed(42)
44+
4345
log = logging.getLogger(__name__)
4446

4547
Verdict = Literal['AC', 'TLE', 'OLE', 'MLE', 'RTE', 'WA', 'PAC', 'JE']
@@ -1017,11 +1019,11 @@ def __str__(self) -> str:
10171019
# Junk data. The validator should reject these cases
10181020
_JUNK_CASES = [
10191021
('an empty file', b''),
1020-
('a binary file with random bytes', bytearray(random.Random(0).randbytes(1024))),
1022+
('a binary file with random bytes', bytearray(random.Random(42).randbytes(1024))),
10211023
('a text file with the ASCII characters 32 up to 127', bytearray(x for x in range(32, 127))),
10221024
(
10231025
'a random text file with printable ASCII characters',
1024-
bytearray(random.choice(string.printable.encode('utf8')) for _ in range(200)),
1026+
(lambda rng: bytearray(rng.choice(string.printable.encode('utf8')) for _ in range(200)))(random.Random(42)),
10251027
),
10261028
]
10271029

@@ -1058,11 +1060,9 @@ def _build_junk_modifier(
10581060

10591061

10601062
_JUNK_MODIFICATIONS = [
1061-
_build_junk_modifier(
1062-
'spaces added where there already is whitespace', r'\s', lambda m: m.group(0) + ' ' * random.randint(1, 5)
1063-
),
1064-
_build_junk_modifier('spaces added to the end of a line', r'\n', lambda m: m.group(0) + ' ' * random.randint(1, 5)),
1065-
_build_junk_modifier('newlines added where there already are newlines', '\n', lambda m: '\n' * random.randint(2, 5)),
1063+
_build_junk_modifier('spaces added where there already is whitespace', r'\s', lambda m: m.group(0) + ' '),
1064+
_build_junk_modifier('spaces added to the end of a line', r'\n', lambda m: m.group(0) + ' '),
1065+
_build_junk_modifier('newlines added where there already are newlines', '\n', lambda m: '\n\n'),
10661066
_build_junk_modifier('leading zeros added to integers', r'(^|[^.]\b)([0-9]+)\b', r'\g<1>0000000000\g<2>'),
10671067
_build_junk_modifier('trailing zeros added to real number decimal portion', r'\.[0-9]+\b', r'\g<0>0000000000'),
10681068
(

0 commit comments

Comments
 (0)