Skip to content

Commit

Permalink
Add tests and score diff calculating for mp and pa
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Sep 13, 2024
1 parent 8a82ece commit 56ba98e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
22 changes: 11 additions & 11 deletions oioioi/contests/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ def factory(self, user, timestamp=None):
request = factory.request()
request.contest = self.contest
request.user = user
request.timestamp = timestamp or self.during
request.timestamp = timestamp or self.during
return request

def setUp(self):
Expand Down Expand Up @@ -3825,7 +3825,7 @@ class TestRulesVisibility(TestCase):
'oioioi.oi.controllers.BOIOnlineContestController',
'oioioi.pa.controllers.PAContestController',
'oioioi.pa.controllers.PAFinalsContestController',
'oioioi.programs.controllers.ProgrammingContestController'
'oioioi.programs.controllers.ProgrammingContestController'
]

# left to fill in when added, in order of the controllers above
Expand Down Expand Up @@ -3905,7 +3905,7 @@ class TestRulesVisibility(TestCase):
None
],
[
datetime(2012, 8, 15, 20, 27, 58, tzinfo=timezone.utc),
datetime(2012, 8, 15, 20, 27, 58, tzinfo=timezone.utc),
datetime(2013, 4, 20, 21, 37, 13, tzinfo=timezone.utc)
],
[
Expand All @@ -3919,12 +3919,12 @@ def _set_problem_limits(self, url, limits_list):
problem = ProblemInstance.objects.get(pk=i+1)
problem.submissions_limit = limits_list[i]
problem.save()

response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)

return response

def _set_results_dates(self, url, dates):
round = Round.objects.get()
round.results_date = dates[0]
Expand All @@ -3947,7 +3947,7 @@ def _change_controller(self, public_results=False):
'oioioi.programs.controllers.ProgrammingContestController'
)
contest.save()

def test_dashboard_view(self):
for c in self.controller_names:
contest = Contest.objects.get()
Expand All @@ -3958,7 +3958,7 @@ def test_dashboard_view(self):
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Rules")

def test_contest_type(self):
for c, d in zip(self.controller_names, self.scoring_descriptions):
contest = Contest.objects.get()
Expand Down Expand Up @@ -4015,7 +4015,7 @@ def test_contest_dates(self):
contest = Contest.objects.get()
contest.controller_name = c
contest.save()

round = Round.objects.get()
round.end_date = None
round.save()
Expand All @@ -4042,7 +4042,7 @@ def test_ranking_visibility(self):
response = self._set_results_dates(url, self.visibility_dates[0])
self.assertContains(response, "In round Round 1, your results as well as " \
"public ranking will be visible after 2012-08-15 20:27:58.")

self._change_controller(public_results=True)
response = self._set_results_dates(url, self.visibility_dates[1])
self.assertContains(response, "In round Round 1, your results will be visible after 2012-08-15 20:27:58" \
Expand All @@ -4054,7 +4054,7 @@ def test_ranking_visibility(self):
with fake_time(datetime(2012, 12, 24, 11, 23, 56, tzinfo=timezone.utc)):
response = self._set_results_dates(url, self.visibility_dates[0])
self.assertContains(response, "In round Round 1, your results as well as public ranking will be visible immediately.")

self._change_controller(public_results=True)
response = self._set_results_dates(url, self.visibility_dates[1])
self.assertContains(response, "In round Round 1, your results will be visible immediately" \
Expand All @@ -4066,7 +4066,7 @@ def test_ranking_visibility(self):
with fake_time(datetime(2014, 8, 26, 11, 23, 56, tzinfo=timezone.utc)):
response = self._set_results_dates(url, self.visibility_dates[0])
self.assertContains(response, "In round Round 1, your results as well as public ranking will be visible immediately.")

self._change_controller(public_results=True)
response = self._set_results_dates(url, self.visibility_dates[1])
self.assertContains(response, "In round Round 1, your results as well as public ranking will be visible immediately.")
Expand Down
15 changes: 15 additions & 0 deletions oioioi/mp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from oioioi.base.tests import TestCase, fake_time
from oioioi.contests.models import Contest, UserResultForProblem
from oioioi.contests.tests.tests import TestScoreDiff
from oioioi.mp.score import FloatScore


Expand Down Expand Up @@ -96,3 +97,17 @@ def test_results_scores(self):
for urfp in UserResultForProblem.objects.all():
res = self._create_result(urfp.user, urfp.problem_instance)
self.assertEqual(res.score, urfp.score)


class TestScoreDiffMPContest(TestScoreDiff):
submission_cls = FloatScore
diff_cls = FloatScore

def test_mp_contest(self):
self._set_contest_controller('oioioi.mp.controllers.MPContestController')
UserResultForProblem.objects.all().delete()

self._test_diff(50., 50.)
self._test_diff(55.5, 5.5)
self._test_diff(0.5, 0)
self._test_diff(100., 44.5)
17 changes: 17 additions & 0 deletions oioioi/pa/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from oioioi.acm.controllers import ACMContestController
from oioioi.base.utils.query_helpers import Q_always_true
from oioioi.base.utils.redirect import safe_redirect
from oioioi.contests.scores import IntegerScore
from oioioi.contests.utils import (
all_non_trial_public_results_visible,
is_contest_admin,
Expand Down Expand Up @@ -201,6 +202,22 @@ def get_default_safe_exec_mode(self):
def get_allowed_languages(self):
return ['C', 'C++', 'Pascal', 'Java']

def calculate_score_change(self, before, after):
if before is None:
if after is None:
return None
return IntegerScore(after.points.value)
return IntegerScore(after.points.value - before.points.value)

def render_score_change(self, diff):
if diff is None:
return '<span class="text-secondary">-</span>'
if diff.value == 0:
return '<span class="text-secondary">0</span>'
if diff.value > 0:
return f'<span class="text-success">+{diff.value}</span>'
return f'<span class="text-danger">{diff.value}</span>'


A_PLUS_B_RANKING_KEY = 'ab'
B_RANKING_KEY = 'b'
Expand Down
11 changes: 11 additions & 0 deletions oioioi/pa/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
UserResultForProblem,
)
from oioioi.contests.scores import IntegerScore
from oioioi.contests.tests.tests import TestScoreDiff
from oioioi.pa import utils
from oioioi.pa.controllers import A_PLUS_B_RANKING_KEY, B_RANKING_KEY
from oioioi.pa.models import PAProblemInstanceData, PARegistration
Expand Down Expand Up @@ -480,3 +481,13 @@ def test_terms_accepted_phrase_inline_edit_restrictions(self):

# Checks if the field is not editable.
self.assertNotContains(response, 'id_terms_accepted_phrase-0-text')


class TestScoreDiffPAContest(TestScoreDiff):
def test_pa_contest(self):
self._set_contest_controller('oioioi.pa.controllers.PAContestController')
UserResultForProblem.objects.all().delete()

self._test_diff(5, 5)
self._test_diff(10, 5)
self._test_diff(0, -10)

0 comments on commit 56ba98e

Please sign in to comment.