From 33eb00211b9d427090b49f48f1ad517abe1087a0 Mon Sep 17 00:00:00 2001 From: Leonard Techel Date: Wed, 19 Jan 2022 21:47:26 +0100 Subject: [PATCH] test(backend): Add missing unit tests for the Parameter model --- backend/dpt_app/trails/tests.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/backend/dpt_app/trails/tests.py b/backend/dpt_app/trails/tests.py index 78a8cca..55d264b 100644 --- a/backend/dpt_app/trails/tests.py +++ b/backend/dpt_app/trails/tests.py @@ -185,3 +185,27 @@ def test_update_clock_last_change(self): self.assertEqual(self.game.clock_state, ClockType.STOPPED) self.assertEqual(self.game.clock_last_change, now) self.assertEqual(self.game.clock_duration, CLOCK_DURATION + 10) + + +class ParameterModelTest(GameTestCase): + def test_value_at(self): + # it returns the parameter value at the requested game duration + self.assertEqual(self.param.value_at( + 0), self.param.initial_value + self.param.value) + + # it does not go below the minimum parameter value + self.assertEqual(self.param.value_at(99999999), self.param.min_value) + + # it does not go above the maximum parameter value + self.assertEqual(self.param.value_at(-99999999), self.param.max_value) + + def test_current_value(self): + # it returns the current parameter value + self.assertEqual(self.param.current_value, 30) + + def test_game_clock_duration_when_value_zero(self): + # it calculates the duration at which the parameter value first gets zero + duration_when_zero = self.param.game_clock_duration_when_value_zero + + self.assertEqual(duration_when_zero, 100) + self.assertEqual(self.param.value_at(duration_when_zero), 0)