Skip to content

Commit

Permalink
fix: dependency tree testcases filename error
Browse files Browse the repository at this point in the history
We rename testcase filename using a counter. However, the dependency test case filenames did not follow the counter.
Currently, TOJ no longer uses a number counter to read test cases, so we can simply use the filenames
  • Loading branch information
tobiichi3227 committed Oct 24, 2024
1 parent aced3f4 commit 521469c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
47 changes: 19 additions & 28 deletions cf2toj.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,52 +91,43 @@ async def main():

tasks_group[group_name] = {
'weight': group_points,
'remap': [],
'data': [],
'dependencies': dependencies,
}
else:
tasks_group[0] = {
'weight': 0,
'remap': [],
'data': [],
'dependencies': [],
}

for idx, test in enumerate(root.findall("./judging/testset/tests/")):
format_str = "{:02}"
for idx, test in enumerate(root.findall("./judging/testset/tests/"), start=1):
g = test.attrib.get('group', 0)

tasks_group[g]['remap'].append(idx + 1)
tasks_group[g]['data'].append(str(idx))

if not groups_enabled:
tasks_group[0]['weight'] = 100
copyfile(
(inputpath, 'tests', format_str.format(idx)),
(tmp_outputpath, 'res/testdata', "{}.in".format(idx)),
)

copyfile(
(inputpath, 'tests', format_str.format(idx) + ".a"),
(tmp_outputpath, 'res/testdata', "{}.out".format(idx)),
)

format_str = "{:02}"
if not groups_enabled:
tasks_group[0]['weight'] = 100

dst = 1
for _, g in tasks_group.items():
g['data'] = []
for src in g['remap']:
copyfile(
(inputpath, 'tests', format_str.format(src)),
(tmp_outputpath, 'res/testdata', "{}.in".format(dst)),
)

copyfile(
(inputpath, 'tests', format_str.format(src) + ".a"),
(tmp_outputpath, 'res/testdata', "{}.out".format(dst)),
)
g['data'].append(dst)
dst += 1

write_group = g.copy()
if args.enable_dependency:
for depend_group in g['dependencies']:
g['data'].extend(tasks_group[depend_group]['remap'])
write_group['data'].extend(tasks_group[depend_group]['data'])

dep = g.pop('dependencies')
remap = g.pop('remap')
conf['test'].append(g.copy())
g['dependencies'] = dep
g['remap'] = remap
write_group.pop('dependencies')
conf['test'].append(write_group)

logging.info('Creating config file')
with open(os.path.join(tmp_outputpath, 'conf.json'), 'w', encoding='utf-8') as conffile:
Expand Down
10 changes: 5 additions & 5 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ def test_with_groups(self):
self.assertEqual(len(conf['test']), 2)

self.assertEqual(int(conf['test'][0]['weight']), 99)
self.assertEqual(conf['test'][0]['data'], list(range(1, 23)))
self.assertEqual(conf['test'][0]['data'], list(map(str, range(1, 23))))
for i in conf['test'][0]['data']:
self.assertTrue(os.path.isfile(f"{test_path}/res/testdata/{i}.in"))
self.assertTrue(os.path.isfile(f"{test_path}/res/testdata/{i}.out"))

self.assertEqual(int(conf['test'][1]['weight']), 1)
self.assertEqual(conf['test'][1]['data'], list(range(23, 124)))
self.assertEqual(conf['test'][1]['data'], list(map(str, range(23, 124))))
for i in conf['test'][1]['data']:
self.assertTrue(os.path.isfile(f"{test_path}/res/testdata/{i}.in"))
self.assertTrue(os.path.isfile(f"{test_path}/res/testdata/{i}.out"))
Expand All @@ -73,19 +73,19 @@ def test_with_dependency(self):
self.assertEqual(len(conf['test']), 3)

self.assertEqual(int(conf['test'][0]['weight']), 1)
self.assertEqual(conf['test'][0]['data'], list(range(1, 2)))
self.assertEqual(conf['test'][0]['data'], list(map(str, range(1, 2))))
for i in conf['test'][0]['data']:
self.assertTrue(os.path.isfile(f"{test_path}/res/testdata/{i}.in"))
self.assertTrue(os.path.isfile(f"{test_path}/res/testdata/{i}.out"))

self.assertEqual(int(conf['test'][1]['weight']), 50)
self.assertEqual(conf['test'][1]['data'], list(range(2, 102)) + list(range(1, 2)))
self.assertEqual(conf['test'][1]['data'], list(map(str, range(2, 102))) + list(map(str, range(1, 2))))
for i in conf['test'][1]['data']:
self.assertTrue(os.path.isfile(f"{test_path}/res/testdata/{i}.in"))
self.assertTrue(os.path.isfile(f"{test_path}/res/testdata/{i}.out"))

self.assertEqual(int(conf['test'][2]['weight']), 49)
self.assertEqual(conf['test'][2]['data'], list(range(102, 201)) + list(range(2, 102)))
self.assertEqual(conf['test'][2]['data'], list(map(str, range(102, 201))) + list(map(str, range(2, 102))))
for i in conf['test'][2]['data']:
self.assertTrue(os.path.isfile(f"{test_path}/res/testdata/{i}.in"))
self.assertTrue(os.path.isfile(f"{test_path}/res/testdata/{i}.out"))
Expand Down

0 comments on commit 521469c

Please sign in to comment.