Coverage for tasks/tests/cia_tests.py: 29%

34 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-30 13:48 +0000

1""" 

2camcops_server/tasks/tests/cia_tests.py 

3 

4=============================================================================== 

5 

6 Copyright (C) 2012, University of Cambridge, Department of Psychiatry. 

7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk). 

8 

9 This file is part of CamCOPS. 

10 

11 CamCOPS is free software: you can redistribute it and/or modify 

12 it under the terms of the GNU General Public License as published by 

13 the Free Software Foundation, either version 3 of the License, or 

14 (at your option) any later version. 

15 

16 CamCOPS is distributed in the hope that it will be useful, 

17 but WITHOUT ANY WARRANTY; without even the implied warranty of 

18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

19 GNU General Public License for more details. 

20 

21 You should have received a copy of the GNU General Public License 

22 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>. 

23 

24=============================================================================== 

25 

26""" 

27 

28from unittest import TestCase 

29 

30from camcops_server.tasks.cia import Cia 

31 

32 

33class CiaTests(TestCase): 

34 def test_complete_when_all_answers_valid(self) -> None: 

35 cia = Cia() 

36 

37 for q_num in range(1, 16 + 1): 

38 setattr(cia, f"q{q_num}", 0) 

39 

40 self.assertTrue(cia.is_complete()) 

41 

42 def test_not_complete_when_not_started(self) -> None: 

43 cia = Cia() 

44 

45 self.assertFalse(cia.is_complete()) 

46 

47 def test_complete_when_all_mandatory_answers_valid(self) -> None: 

48 cia = Cia() 

49 

50 for q_num in (1, 2, 5, 6, 8, 9, 11, 12, 13, 14, 15, 16): 

51 setattr(cia, f"q{q_num}", 3) 

52 

53 self.assertTrue(cia.is_complete()) 

54 

55 def test_max_global_score_for_all_answers(self) -> None: 

56 cia = Cia() 

57 

58 for q_num in range(1, 16 + 1): 

59 setattr(cia, f"q{q_num}", 3) 

60 

61 self.assertEqual(cia.global_score(), 48) 

62 

63 def test_global_score_is_prorated_for_mandatory_questions(self) -> None: 

64 cia = Cia() 

65 

66 for q_num in (1, 2, 5, 6, 8, 9, 11, 12, 13, 14, 15, 16): 

67 setattr(cia, f"q{q_num}", 3) 

68 

69 self.assertEqual(cia.global_score(), 48) 

70 

71 def test_global_score_is_not_rated_when_mandatory_questions_not_answered( 

72 self, 

73 ) -> None: 

74 cia = Cia() 

75 

76 for q_num in (3, 4, 7, 10): 

77 setattr(cia, f"q{q_num}", 3) 

78 

79 self.assertIsNone(cia.global_score()) 

80 

81 def test_global_score_is_not_rated_for_any_unanswered_questions( 

82 self, 

83 ) -> None: 

84 cia = Cia() 

85 

86 self.assertIsNone(cia.global_score())