Skip to content

Commit fdcdcd7

Browse files
authored
Merge pull request #310 from FilipKon13/main
Add total_score to config.yml
2 parents 3adcdd9 + 8ab9c0e commit fdcdcd7

File tree

12 files changed

+750
-5
lines changed

12 files changed

+750
-5
lines changed

example_package/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ sinol_latex_compiler: auto
8787
# This key is optional and should be a list of tests.
8888
sinol_static_tests: ["__ID__0.in", "__ID__0a.in"]
8989

90+
# Total score of the task is defined in `sinol_total_score` key.
91+
# If this key is not specified, then this defaults to 100.
92+
sinol_total_score: 100
93+
9094
# sinol-make can check if the solutions run as expected when using `run` command.
9195
# Key `sinol_expected_scores` defines expected scores for each solution on each tests.
9296
# There should be no reason to change this key manually.

src/sinol_make/commands/run/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,10 @@ def set_scores(self):
827827
self.scores[group] = self.config["scores"][group]
828828
total_score += self.scores[group]
829829

830-
if total_score != 100:
831-
print(util.warning("WARN: Scores sum up to %d instead of 100." % total_score))
830+
total_score_config = 100 if 'sinol_total_score' not in self.config.keys() else self.config['sinol_total_score']
831+
832+
if total_score != total_score_config:
833+
print(util.warning("WARN: Scores sum up to %d instead of %d." % (total_score, total_score_config)))
832834
print()
833835

834836
self.possible_score = self.contest.get_possible_score(self.groups, self.scores)

src/sinol_make/contest_types/oij.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ def argument_overrides(self, args: argparse.Namespace) -> argparse.Namespace:
2222

2323
def verify_pre_gen(self):
2424
"""
25-
Verify if scores sum up to 100.
25+
Verify if scores sum up correctly.
2626
"""
2727
config = package_util.get_config()
2828
if 'scores' not in config:
2929
util.exit_with_error("Scores are not defined in config.yml.")
3030
total_score = sum(config['scores'].values())
31-
if total_score != 100:
32-
util.exit_with_error(f"Total score in config is {total_score}, but should be 100.")
31+
total_score_config = 100 if 'sinol_total_score' not in config else config['sinol_total_score']
32+
33+
if total_score != total_score_config:
34+
util.exit_with_error(f"Total score in config is {total_score}, but should be {total_score_config}.")
3335

3436
def verify_tests_order(self):
3537
return True

tests/commands/verify/test_integration.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,37 @@ def test_no_gen_parameters(capsys, create_package):
174174
run(["--no-ingen"])
175175
assert os.path.exists(os.path.join(create_package, "in", "abc2a.in"))
176176
assert os.path.exists(os.path.join(create_package, "out", "abc2a.out"))
177+
178+
@pytest.mark.parametrize("create_package", [util.get_score_package()], indirect=True)
179+
def test_total_score_in_config(capsys, create_package):
180+
"""
181+
Test if total score overwrites default 100 for verification if contest type is OIJ.
182+
"""
183+
run()
184+
185+
if os.path.exists(paths.get_cache_path()):
186+
shutil.rmtree(paths.get_cache_path())
187+
cache.create_cache_dirs()
188+
config = package_util.get_config()
189+
config["sinol_total_score"] = 25
190+
sm_util.save_config(config)
191+
with pytest.raises(SystemExit) as e:
192+
run()
193+
assert e.value.code == 1
194+
out = capsys.readouterr().out
195+
assert "Total score in config is 40, but should be 25." in out
196+
197+
198+
@pytest.mark.parametrize("create_package", [util.get_score_package()], indirect=True)
199+
def test_total_score_in_config_oi(capsys, create_package):
200+
"""
201+
Test if total_score does not overwrite default 100 for verification if contest type is OI.
202+
"""
203+
config = package_util.get_config()
204+
config["sinol_contest_type"] = "oi"
205+
sm_util.save_config(config)
206+
with pytest.raises(SystemExit) as e:
207+
run()
208+
assert e.value.code == 1
209+
out = capsys.readouterr().out
210+
assert "Total score in config is 40, but should be 100." in out

tests/packages/score/config.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
title: Package for testing sinol_total_score configuration
2+
sinol_task_id: score
3+
sinol_contest_type: oij
4+
memory_limit: 16000
5+
time_limit: 1000
6+
sinol_total_score: 40
7+
scores:
8+
1: 10
9+
2: 10
10+
3: 10
11+
4: 10
12+
sinol_expected_scores:
13+
score.cpp:
14+
expected:
15+
1: {points: 10, status: OK}
16+
2: {points: 10, status: OK}
17+
3: {points: 10, status: OK}
18+
4: {points: 10, status: OK}
19+
points: 40

tests/packages/score/doc/.gitkeep

Whitespace-only changes.

tests/packages/score/in/.gitkeep

Whitespace-only changes.

tests/packages/score/out/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)