Coverage for tasks/tests/aq_tests.py: 30%

1"""

2 camcops_server/tasks/tests/aq_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

28 from unittest import TestCase

29

30 from camcops_server.tasks.aq import Aq

31

32

33 class AqTests(TestCase):

34 AGREE_SCORING_QUESTIONS = [

35 2,

36 4,

37 5,

38 6,

39 7,

40 9,

41 12,

42 13,

43 16,

44 18,

45 19,

46 20,

47 21,

48 22,

49 23,

50 26,

51 33,

52 35,

53 39,

54 41,

55 42,

56 43,

57 45,

58 46,

59 ]

60

61 DISAGREE_SCORING_QUESTIONS = [

62 1,

63 3,

64 8,

65 10,

66 11,

67 14,

68 15,

69 17,

70 24,

71 25,

72 27,

73 28,

74 29,

75 30,

76 31,

77 32,

78 34,

79 36,

80 37,

81 38,

82 40,

83 44,

84 47,

85 48,

86 49,

87 50,

88 ]

89

90 ALL_QUESTIONS = range(1, 50 + 1)

91

92 DEFINITELY_AGREE = 0

93 DEFINITELY_DISAGREE = 3

94

95 SOCIAL_SKILL_QUESTIONS = [1, 11, 13, 15, 22, 36, 44, 45, 47, 48]

96 ATTENTION_SWITCHING_QUESTIONS = [2, 4, 10, 16, 25, 32, 34, 37, 43, 46]

97 ATTENTION_TO_DETAIL_QUESTIONS = [5, 6, 9, 12, 19, 23, 28, 29, 30, 49]

98 COMMUNICATION_QUESTIONS = [7, 17, 18, 26, 27, 31, 33, 35, 38, 39]

99 IMAGINATION_QUESTIONS = [3, 8, 14, 20, 21, 24, 40, 41, 42, 50]

100

101 def test_max_score_is_50(self):

102 aq = Aq()

103 for q_num in self.AGREE_SCORING_QUESTIONS:

104 setattr(aq, f"q{q_num}", self.DEFINITELY_AGREE)

105

106 for q_num in self.DISAGREE_SCORING_QUESTIONS:

107 setattr(aq, f"q{q_num}", self.DEFINITELY_DISAGREE)

108

109 self.assertEqual(aq.score(), 50)

110

111 def test_min_score_is_0(self):

112 aq = Aq()

113

114 for q_num in self.AGREE_SCORING_QUESTIONS:

115 setattr(aq, f"q{q_num}", self.DEFINITELY_DISAGREE)

116

117 for q_num in self.DISAGREE_SCORING_QUESTIONS:

118 setattr(aq, f"q{q_num}", self.DEFINITELY_AGREE)

119

120 self.assertEqual(aq.score(), 0)

121

122 def test_score_is_none_if_any_none(self):

123 aq = Aq()

124

125 for q_num in self.ALL_QUESTIONS:

126 setattr(aq, f"q{q_num}", self.DEFINITELY_AGREE)

127

128 aq.q1 = None

129

130 self.assertIsNone(aq.score())

131

132 def test_incomplete_when_answers_missing(self):

133 aq = Aq()

134

135 self.assertFalse(aq.is_complete())

136

137 def test_complete_when_all_answered(self):

138 aq = Aq()

139

140 for q_num in self.ALL_QUESTIONS:

141 setattr(aq, f"q{q_num}", self.DEFINITELY_AGREE)

142

143 self.assertTrue(aq.is_complete())

144

145 def test_social_skill_score_is_none_if_any_none(self):

146 aq = Aq()

147

148 for q_num in self.SOCIAL_SKILL_QUESTIONS:

149 setattr(aq, f"q{q_num}", self.non_scoring_answer(q_num))

150

151 aq.q1 = None

152

153 self.assertIsNone(aq.social_skill_score())

154

155 def test_min_social_skill_score_is_0(self):

156 aq = Aq()

157

158 for q_num in self.SOCIAL_SKILL_QUESTIONS:

159 setattr(aq, f"q{q_num}", self.non_scoring_answer(q_num))

160

161 self.assertEqual(aq.social_skill_score(), 0)

162

163 def test_max_social_skill_score_is_10(self):

164 aq = Aq()

165

166 for q_num in self.SOCIAL_SKILL_QUESTIONS:

167 setattr(aq, f"q{q_num}", self.scoring_answer(q_num))

168

169 self.assertEqual(aq.social_skill_score(), 10)

170

171 def test_min_attention_switching_score_is_0(self):

172 aq = Aq()

173

174 for q_num in self.ATTENTION_SWITCHING_QUESTIONS:

175 setattr(aq, f"q{q_num}", self.non_scoring_answer(q_num))

176

177 self.assertEqual(aq.attention_switching_score(), 0)

178

179 def test_max_attention_switching_score_is_10(self):

180 aq = Aq()

181

182 for q_num in self.ATTENTION_SWITCHING_QUESTIONS:

183 setattr(aq, f"q{q_num}", self.scoring_answer(q_num))

184

185 self.assertEqual(aq.attention_switching_score(), 10)

186

187 def test_min_attention_to_detail_score_is_0(self):

188 aq = Aq()

189

190 for q_num in self.ATTENTION_TO_DETAIL_QUESTIONS:

191 setattr(aq, f"q{q_num}", self.non_scoring_answer(q_num))

192

193 self.assertEqual(aq.attention_to_detail_score(), 0)

194

195 def test_max_attention_to_detail_score_is_10(self):

196 aq = Aq()

197

198 for q_num in self.ATTENTION_TO_DETAIL_QUESTIONS:

199 setattr(aq, f"q{q_num}", self.scoring_answer(q_num))

200

201 self.assertEqual(aq.attention_to_detail_score(), 10)

202

203 def test_min_communication_score_is_0(self):

204 aq = Aq()

205

206 for q_num in self.COMMUNICATION_QUESTIONS:

207 setattr(aq, f"q{q_num}", self.non_scoring_answer(q_num))

208

209 self.assertEqual(aq.communication_score(), 0)

210

211 def test_max_communication_score_is_10(self):

212 aq = Aq()

213

214 for q_num in self.COMMUNICATION_QUESTIONS:

215 setattr(aq, f"q{q_num}", self.scoring_answer(q_num))

216

217 self.assertEqual(aq.communication_score(), 10)

218

219 def test_min_imagination_score_is_0(self):

220 aq = Aq()

221

222 for q_num in self.IMAGINATION_QUESTIONS:

223 setattr(aq, f"q{q_num}", self.non_scoring_answer(q_num))

224

225 self.assertEqual(aq.imagination_score(), 0)

226

227 def test_max_imagination_score_is_10(self):

228 aq = Aq()

229

230 for q_num in self.IMAGINATION_QUESTIONS:

231 setattr(aq, f"q{q_num}", self.scoring_answer(q_num))

232

233 self.assertEqual(aq.imagination_score(), 10)

234

235 def non_scoring_answer(self, q_num: int):

236 if q_num in self.AGREE_SCORING_QUESTIONS:

237 return self.DEFINITELY_DISAGREE

238

239 return self.DEFINITELY_AGREE

240

241 def scoring_answer(self, q_num: int):

242 if q_num in self.AGREE_SCORING_QUESTIONS:

243 return self.DEFINITELY_AGREE

244

245 return self.DEFINITELY_DISAGREE