diff --git a/cf2toj.py b/cf2toj.py index d646530..8895315 100644 --- a/cf2toj.py +++ b/cf2toj.py @@ -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: diff --git a/tests/tests.py b/tests/tests.py index 4dd35c1..613d38b 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -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")) @@ -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"))