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

35 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-08 23:14 +0000

1#!/usr/bin/env python 

2 

3""" 

4camcops_server/tasks/tests/cia_tests.py 

5 

6=============================================================================== 

7 

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

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

10 

11 This file is part of CamCOPS. 

12 

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. 

17 

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. 

22 

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/>. 

25 

26=============================================================================== 

27 

28""" 

29 

30from unittest import TestCase 

31 

32from camcops_server.tasks.cia import Cia 

33 

34 

35class CiaTests(TestCase): 

36 def test_complete_when_all_answers_valid(self) -> None: 

37 cia = Cia() 

38 

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

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

41 

42 self.assertTrue(cia.is_complete()) 

43 

44 def test_not_complete_when_not_started(self) -> None: 

45 cia = Cia() 

46 

47 self.assertFalse(cia.is_complete()) 

48 

49 def test_complete_when_all_mandatory_answers_valid(self) -> None: 

50 cia = Cia() 

51 

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

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

54 

55 self.assertTrue(cia.is_complete()) 

56 

57 def test_max_global_score_for_all_answers(self) -> None: 

58 cia = Cia() 

59 

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

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

62 

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

64 

65 def test_global_score_is_prorated_for_mandatory_questions(self) -> None: 

66 cia = Cia() 

67 

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

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

70 

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

72 

73 def test_global_score_is_not_rated_when_mandatory_questions_not_answered( 

74 self, 

75 ) -> None: 

76 cia = Cia() 

77 

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

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

80 

81 self.assertIsNone(cia.global_score()) 

82 

83 def test_global_score_is_not_rated_for_any_unanswered_questions( 

84 self, 

85 ) -> None: 

86 cia = Cia() 

87 

88 self.assertIsNone(cia.global_score())