Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -87,6 +87,10 @@ sinol_latex_compiler: auto
# This key is optional and should be a list of tests.
sinol_static_tests: ["__ID__0.in", "__ID__0a.in"]

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

# sinol-make can check if the solutions run as expected when using `run` command.
# Key `sinol_expected_scores` defines expected scores for each solution on each tests.
# There should be no reason to change this key manually.
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 'sinol_total_score' not in self.config.keys() else self.config['sinol_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 'sinol_total_score' not in config else config['sinol_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["sinol_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 sinol_total_score configuration
sinol_task_id: score
sinol_contest_type: oij
memory_limit: 16000
time_limit: 1000
sinol_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
Loading