Coverage for tasks/tests/paradise24_tests.py: 30%
30 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
1#!/usr/bin/env python
3"""
4camcops_server/tasks/tests/paradise24_tests.py
6===============================================================================
8 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
9 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
11 This file is part of CamCOPS.
13 CamCOPS is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
18 CamCOPS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
26===============================================================================
28"""
30from unittest import mock, TestCase
32from camcops_server.tasks.paradise24 import Paradise24
35class Paradise24Tests(TestCase):
36 def test_complete_when_all_answers_valid(self) -> None:
37 paradise24 = Paradise24()
39 for q_num in range(1, 24 + 1):
40 setattr(paradise24, f"q{q_num}", 0)
42 self.assertTrue(paradise24.is_complete())
44 def test_is_complete_false_when_not_finished(self) -> None:
45 paradise24 = Paradise24()
47 self.assertFalse(paradise24.is_complete())
49 def test_total_score_none_when_not_complete(self) -> None:
50 paradise24 = Paradise24()
52 self.assertIsNone(paradise24.total_score())
54 def test_total_score_is_sum_of_all_answers(self) -> None:
55 paradise24 = Paradise24()
57 for q_num in range(1, 24 + 1):
58 setattr(paradise24, f"q{q_num}", 2)
60 self.assertEqual(paradise24.total_score(), 48)
62 def test_metric_score_derived_from_total(self) -> None:
63 paradise24 = Paradise24()
65 # Not an exhaustive test of all values as that would not be
66 # particularly useful. Enough to check the lookup
67 # is working.
68 paradise24.total_score = mock.Mock(return_value=48)
69 self.assertEqual(paradise24.metric_score(), 100)
71 paradise24.total_score = mock.Mock(return_value=24)
72 self.assertEqual(paradise24.metric_score(), 64)
74 paradise24.total_score = mock.Mock(return_value=0)
75 self.assertEqual(paradise24.metric_score(), 0)
77 paradise24.total_score = mock.Mock(return_value=None)
78 self.assertIsNone(paradise24.metric_score())