Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions example_package/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ scores:
1: 40
2: 60

# Total score of the task is defined in `total_score` key.
# If this key is not specified, then this defaults to 100.
total_score: 100

# Time limit for all tests is defined in `time_limit` key.
# More precise time limit for each group or test can be defined in `time_limits` key.
# The more precise time limit has higher priority (first group, then global time limit).
Expand Down
6 changes: 4 additions & 2 deletions src/sinol_make/commands/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,10 @@ def set_scores(self):
self.scores[group] = self.config["scores"][group]
total_score += self.scores[group]

if total_score != 100:
print(util.warning("WARN: Scores sum up to %d instead of 100." % total_score))
total_score_config = 100 if 'total_score' not in self.config.keys() else self.config['total_score']

if total_score != total_score_config:
print(util.warning("WARN: Scores sum up to %d instead of %d." % (total_score, total_score_config)))
print()

self.possible_score = self.contest.get_possible_score(self.groups, self.scores)
Expand Down
8 changes: 5 additions & 3 deletions src/sinol_make/contest_types/oij.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ def argument_overrides(self, args: argparse.Namespace) -> argparse.Namespace:

def verify_pre_gen(self):
"""
Verify if scores sum up to 100.
Verify if scores sum up correctly.
"""
config = package_util.get_config()
if 'scores' not in config:
util.exit_with_error("Scores are not defined in config.yml.")
total_score = sum(config['scores'].values())
if total_score != 100:
util.exit_with_error(f"Total score in config is {total_score}, but should be 100.")
total_score_config = 100 if 'total_score' not in config else config['total_score']

if total_score != total_score_config:
util.exit_with_error(f"Total score in config is {total_score}, but should be {total_score_config}.")

def verify_tests_order(self):
return True
34 changes: 34 additions & 0 deletions tests/commands/verify/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,37 @@ def test_no_gen_parameters(capsys, create_package):
run(["--no-ingen"])
assert os.path.exists(os.path.join(create_package, "in", "abc2a.in"))
assert os.path.exists(os.path.join(create_package, "out", "abc2a.out"))

@pytest.mark.parametrize("create_package", [util.get_score_package()], indirect=True)
def test_total_score_in_config(capsys, create_package):
"""
Test if total_score overwrites default 100 for verification if contest type is OIJ.
"""
run()

if os.path.exists(paths.get_cache_path()):
shutil.rmtree(paths.get_cache_path())
cache.create_cache_dirs()
config = package_util.get_config()
config["total_score"] = 25
sm_util.save_config(config)
with pytest.raises(SystemExit) as e:
run()
assert e.value.code == 1
out = capsys.readouterr().out
assert "Total score in config is 40, but should be 25." in out


@pytest.mark.parametrize("create_package", [util.get_score_package()], indirect=True)
def test_total_score_in_config_oi(capsys, create_package):
"""
Test if total_score does not overwrite default 100 for verification if contest type is OI.
"""
config = package_util.get_config()
config["sinol_contest_type"] = "oi"
sm_util.save_config(config)
with pytest.raises(SystemExit) as e:
run()
assert e.value.code == 1
out = capsys.readouterr().out
assert "Total score in config is 40, but should be 100." in out
19 changes: 19 additions & 0 deletions tests/packages/score/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
title: Package for testing total_score configuration
sinol_task_id: score
sinol_contest_type: oij
memory_limit: 16000
time_limit: 1000
total_score: 40
scores:
1: 10
2: 10
3: 10
4: 10
sinol_expected_scores:
score.cpp:
expected:
1: {points: 10, status: OK}
2: {points: 10, status: OK}
3: {points: 10, status: OK}
4: {points: 10, status: OK}
points: 40
Empty file.
Empty file.
Empty file.
Loading