]> Git — Sourcephile - majurity.git/blob - test/HUnit.hs
Add support for multiple choices in Section.
[majurity.git] / test / HUnit.hs
1 {-# LANGUAGE OverloadedLists #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
3 module HUnit where
4
5 import Test.Tasty
6 import Test.Tasty.HUnit
7
8 import Control.Arrow (second)
9 import Data.Hashable (Hashable)
10 import Data.Ratio ((%))
11 import Data.Tree (Tree(..))
12 import GHC.Exts (IsList(..))
13 import Prelude
14 import qualified Data.HashMap.Strict as HM
15
16 import Hjugement
17 import Types
18
19 hunits :: TestTree
20 hunits =
21 testGroup "HUnit"
22 [ testGroup "MajorityValue" $
23 [ testCompareValue
24 [(3,15), (2,7), (1,3), (0::Int,2)]
25 [(3,16), (2,6), (1,2), (0,3)]
26 , testGroup "Merit"
27 [ let m = mkMerit ['A'..'F'] in
28 testMajorityValueOfMerits
29 [ (The, m [136,307,251,148,84,74])
30 ]
31 [ (The, [('C',251),('B',307),('D',148),('E',84),('A',136),('F',74)])
32 ]
33 , let m = mkMerit [ToReject .. TooGood] in
34 testMajorityValueOfMerits
35 [ (This, m [12,10,21,5,5,5,2])
36 , (That, m [12,16,22,3,3,3,1])
37 ]
38 [ (This, [(Acceptable,21),(Insufficient,10),(Good,5),(ToReject,12),(Perfect,5),(VeryGood,5),(TooGood,2)])
39 , (That, [(Acceptable,22),(Insufficient,16),(ToReject,12),(VeryGood,3),(Perfect,3),(Good,3),(TooGood,1)])
40 ]
41 ]
42 , testGroup "MajorityRanking"
43 [ testMajorityValueOfOpinions
44 [ (The, [No,No,No,No,Yes,Yes]) ]
45 [ (The, [(No,4),(Yes,2)]) ]
46 , testMajorityValueOfOpinions
47 [ (The, [No,No,No,Yes,Yes,Yes]) ]
48 [ (The, [(No,3),(Yes,3)]) ]
49 , testMajorityValueOfOpinions
50 [ (This, [No,No,No,No,Yes,Yes])
51 , (That, [No,Yes,Yes,Yes,Yes,Yes])
52 ]
53 [ (This, [(No,4),(Yes,2)])
54 , (That, [(Yes,5),(No,1)])
55 ]
56 , testMajorityValueOfOpinions
57 [ (This, [No,No,No,No,No,No])
58 , (That, [No,No,No,Yes,Yes,Yes])
59 ]
60 [ (This, [(No,6)])
61 , (That, [(No,3),(Yes,3)])
62 ]
63 , testMajorityValueOfOpinions
64 [ (This, [Yes,Yes,Yes,Yes,Yes,Yes])
65 , (That, [No,No,No,Yes,Yes,Yes])
66 ]
67 [ (This, [(Yes,6)])
68 , (That, [(No,3),(Yes,3)])
69 ]
70 , testMajorityValueOfOpinions
71 [ (This, [No,No,Yes,Yes,Yes,Yes])
72 , (That, [No,No,No,Yes,Yes,Yes])
73 ]
74 [ (This, [(Yes,4),(No,2)])
75 , (That, [(No,3),(Yes,3)])
76 ]
77 , testMajorityValueOfOpinions
78 [ (1::Int, [Perfect,Perfect,VeryGood,Perfect,Perfect,Perfect])
79 , (2, [Perfect,VeryGood,VeryGood,VeryGood,Good,VeryGood])
80 , (3, [Acceptable,Perfect,Good,VeryGood,VeryGood,Perfect])
81 , (4, [VeryGood,Good,Acceptable,Good,Good,Good])
82 , (5, [Good,Acceptable,VeryGood,Good,Good,Good])
83 , (6, [VeryGood,Acceptable,Insufficient,Acceptable,Acceptable,Good])
84 ]
85 [ (1, [(Perfect,5),(VeryGood,1)])
86 , (2, [(VeryGood,4),(Good,1),(Perfect,1)])
87 , (3, [(VeryGood,2),(Good,1),(Perfect,2),(Acceptable,1)])
88 , (4, [(Good,4),(Acceptable,1),(VeryGood,1)])
89 , (5, [(Good,4),(Acceptable,1),(VeryGood,1)])
90 , (6, [(Acceptable,3),(Good,1),(Insufficient,1),(VeryGood,1)])
91 ]
92 ]
93 , testGroup "Section"
94 [ testSection "0 judge"
95 ([]::Choices C2)
96 ([]::Judges Int G6)
97 (node0 [])
98 (Right $ node0 [])
99 , testSection "1 judge, default grade"
100 [This]
101 [(1::Int,ToReject)]
102 (node0 [])
103 (Right $ node0 [(This, [(1,[(ToReject,1%1)])])])
104 , testSection "1 judge, default grade, 2 choices"
105 [This, That]
106 [(1::Int,ToReject)]
107 (node0 [])
108 (Right $ node0 [ (This, [(1,[(ToReject,1%1)])])
109 , (That, [(1,[(ToReject,1%1)])])
110 ])
111 , testSection "1 judge, default grade"
112 [This]
113 [(1::Int,ToReject)]
114 (node0 [(This,[(1,Section Nothing Nothing)])])
115 (Right $ node0 [(This,[(1,[(ToReject,1%1)])])])
116 , testSection "2 judges, default grade"
117 [This]
118 [(1::Int,ToReject), (2::Int,ToReject)]
119 (node0
120 [ (This, [(1,Section Nothing Nothing)])
121 ])
122 (Right $ node0
123 [ (This, [ (1,[(ToReject,1%1)])
124 , (2,[(ToReject,1%1)])
125 ])
126 ])
127 , testSection "ErrorSection_unknown_choices"
128 []
129 [(1::Int,ToReject)]
130 (node0 [(This,[])])
131 (Left $ ErrorSection_unknown_choices [This])
132 , testSection "ErrorSection_unknown_choices"
133 []
134 [(1::Int,ToReject)]
135 (node0 [(This,[(2,Section Nothing Nothing)])])
136 (Left $ ErrorSection_unknown_choices [This])
137 , testSection "ErrorSection_unknown_choices"
138 [This]
139 [(1::Int,ToReject)]
140 (node0 [ (This,[(1,Section Nothing Nothing)])
141 , (That,[(2,Section Nothing Nothing)])
142 ])
143 (Left $ ErrorSection_unknown_choices [That])
144 , testSection "ErrorSection_unknown_judges"
145 [This]
146 [(1::Int,ToReject)]
147 (node0 [(This,[(2,Section Nothing Nothing)])])
148 (Left $ ErrorSection_unknown_judges [(This,[2])])
149 , testSection "1 judge, 1 grade"
150 [This]
151 [(1::Int,ToReject)]
152 (node0 [(This,[(1,Section Nothing (Just Acceptable))])])
153 (Right $ node0 [(This,[(1,[(Acceptable,1%1)])])])
154 , testSection "1 judge, 1 grade, 2 sections"
155 [This]
156 [(1::Int,ToReject)]
157 (Node
158 [ (This, [(1,Section Nothing (Just Acceptable))]) ]
159 [ node0 [(This, [(1,Section (Just $ 1%2) Nothing)])]
160 , node0 [(This, [(1,Section (Just $ 1%2) Nothing)])]
161 ])
162 (Right $ Node
163 [ (This, [(1,[(Acceptable,1%1)])]) ]
164 [ node0 [(This, [(1,[(Acceptable,1%1)])])]
165 , node0 [(This, [(1,[(Acceptable,1%1)])])]
166 ])
167 , testSection "1 judge, 2 grades, 2 sections"
168 [This]
169 [(1::Int,ToReject)]
170 (Node
171 [ (This, [(1,Section Nothing (Just Acceptable))]) ]
172 [ node0 [(This, [(1,Section (Just $ 1%2) Nothing)])]
173 , node0 [(This, [(1,Section (Just $ 1%2) (Just Good))])]
174 ])
175 (Right $ Node
176 [(This, [(1,[(Acceptable,1%2), (Good,1%2)])])]
177 [ node0 [(This, [(1,[(Acceptable,1%1)])])]
178 , node0 [(This, [(1,[(Good,1%1)])])]
179 ])
180 , testSection "1 judge, 2 grades, 2 sections (1 default)"
181 [This]
182 [(1::Int,ToReject)]
183 (Node
184 [ (This, [(1,Section Nothing (Just Acceptable))]) ]
185 [ node0 [(This, [(1,Section Nothing Nothing)])]
186 , node0 [(This, [(1,Section (Just $ 1%2) (Just Good))])]
187 ])
188 (Right $ Node
189 [(This, [(1,[(Acceptable,1%2), (Good,1%2)])])]
190 [ node0 [(This, [(1,[(Acceptable,1%1)])])]
191 , node0 [(This, [(1,[(Good,1%1)])])]
192 ])
193 , testSection "1 judge, 3 grades, 3 sections (2 default)"
194 [This]
195 [(1::Int,ToReject)]
196 (Node
197 [ (This, [(1,Section Nothing (Just Acceptable))]) ]
198 [ node0 [(This, [(1,Section Nothing Nothing)])]
199 , node0 [(This, [(1,Section (Just $ 1%2) (Just Good))])]
200 , node0 [(This, [(1,Section Nothing (Just VeryGood))])]
201 ])
202 (Right $ Node
203 [(This, [(1,[(Acceptable,1%4), (Good,1%2), (VeryGood,1%4)])])]
204 [ node0 [(This, [(1,[(Acceptable,1%1)])])]
205 , node0 [(This, [(1,[(Good,1%1)])])]
206 , node0 [(This, [(1,[(VeryGood,1%1)])])]
207 ])
208 , testSection "ErrorSection_invalid_shares sum not 1"
209 [This]
210 [(1::Int,ToReject)]
211 (Node
212 [ (This, [(1,Section Nothing (Just Acceptable))]) ]
213 [ node0 [(This, [(1,Section (Just $ 1%2) Nothing)])]
214 , node0 [(This, [(1,Section (Just $ 1%3) (Just Good))])]
215 ])
216 (Left $ ErrorSection_invalid_shares [(This, [(1,[1%2,1%3])])])
217 , testSection "ErrorSection_invalid_shares negative share"
218 [This]
219 [(1::Int,ToReject)]
220 (Node
221 [ (This, [(1,Section Nothing (Just Acceptable))]) ]
222 [ node0 [(This, [(1,Section (Just $ 1%2) Nothing)])]
223 , node0 [(This, [(1,Section (Just $ -1%2) (Just Good))])]
224 ])
225 (Left $ ErrorSection_invalid_shares [(This, [(1,[1%2,-1%2])])])
226 , testSection "2 judges, 3 grade, 3 sections (1 default)"
227 [This]
228 [(1::Int,ToReject), (2::Int,ToReject)]
229 (Node
230 [ (This, [(1,Section Nothing (Just Acceptable))])
231 ]
232 [ node0
233 [ (This, [(1,Section Nothing Nothing)])
234 ]
235 , node0
236 [ (This, [(1,Section (Just $ 1%2) (Just Good))])
237 ]
238 ])
239 (Right $ Node
240 [ (This, [ (1,[(Acceptable,1%2), (Good,1%2)])
241 , (2,[(ToReject,1%1)])
242 ])
243 ]
244 [ node0
245 [ (This, [ (1,[(Acceptable,1%1)])
246 , (2,[(ToReject,1%1)])
247 ])
248 ]
249 , node0
250 [ (This, [ (1,[(Good,1%1)])
251 , (2,[(ToReject,1%1)])
252 ])
253 ]
254 ])
255 , testSection "2 judges, 4 grades, 5 sections (2 defaults)"
256 [This]
257 [(1::Int,ToReject), (2::Int,ToReject)]
258 (Node
259 [ (This, [(1,Section Nothing (Just Acceptable))])
260 ]
261 [ node0
262 [ (This, [(1,Section Nothing Nothing)])
263 ]
264 , node0
265 [ (This, [(1,Section (Just $ 1%2) (Just Good))])
266 ]
267 , Node
268 [ (This, [(1,Section Nothing (Just Good))])
269 ]
270 [ node0
271 [ (This, [ (1,Section Nothing (Just VeryGood))
272 , (2,Section Nothing (Just Insufficient))
273 ])
274 ]
275 ]
276 ])
277 (Right $ Node
278 [ (This, [ (1,[(Acceptable,1%4), (Good,1%2), (VeryGood,1%4)])
279 , (2,[(ToReject,2%3), (Insufficient,1%3)])
280 ])
281 ]
282 [ node0
283 [ (This, [ (1,[(Acceptable,1%1)])
284 , (2,[(ToReject,1%1)])
285 ])
286 ]
287 , node0
288 [ (This, [ (1,[(Good,1%1)])
289 , (2,[(ToReject,1%1)])
290 ])
291 ]
292 , Node
293 [ (This, [ (1,[(VeryGood,1%1)])
294 , (2,[(Insufficient,1%1)])
295 ])
296 ]
297 [ node0
298 [ (This, [ (1,[(VeryGood,1%1)])
299 , (2,[(Insufficient,1%1)])
300 ])
301 ]
302 ]
303 ])
304 , testSection "1 judge, default grade, 2 choices"
305 [This, That]
306 [(1::Int,ToReject)]
307 (node0 [])
308 (Right $ node0 [ (This,[(1,[(ToReject,1%1)])])
309 , (That,[(1,[(ToReject,1%1)])])
310 ])
311 , testSection "2 judges, 2 choices"
312 [This, That]
313 [(1::Int,ToReject), (2::Int,ToReject)]
314 (Node
315 [ ]
316 [ node0
317 [ (This, [(1,Section Nothing (Just Good))])
318 , (That, [(2,Section Nothing (Just Insufficient))])
319 ]
320 , node0
321 [ (This, [(1,Section Nothing (Just Acceptable))])
322 , (That, [(2,Section Nothing (Just VeryGood))])
323 ]
324 ])
325 (Right $ Node
326 [ (This, [ (1,[(Good,1%2), (Acceptable,1%2)])
327 , (2,[(ToReject,1%1)])
328 ])
329 , (That, [ (1,[(ToReject,1%1)])
330 , (2,[(Insufficient,1%2), (VeryGood,1%2)])
331 ])
332 ]
333 [ node0 [ (This, [ (1,[(Good,1%1)])
334 , (2,[(ToReject,1%1)])
335 ])
336 , (That, [ (1,[(ToReject,1%1)])
337 , (2,[(Insufficient,1%1)])
338 ])
339 ]
340 , node0 [ (This, [ (1,[(Acceptable,1%1)])
341 , (2,[(ToReject,1%1)])
342 ])
343 , (That, [ (1,[(ToReject,1%1)])
344 , (2,[(VeryGood,1%1)])
345 ])
346 ]
347 ])
348 , testSection "1 judge, 1 choice"
349 [This]
350 [(1::Int,ToReject)]
351 (Node []
352 [ node0 [ (This, [(1,Section (Just $ 1%8) (Just Acceptable))])
353 ]
354 , node0 [ (This, [(1,Section Nothing Nothing)])
355 ]
356 ])
357 (Right $ Node
358 [ (This, [(1,[(Acceptable,1%8), (ToReject,7%8)])])
359 ]
360 [ node0 [ (This, [(1,[(Acceptable, 1%1)])])
361 ]
362 , node0 [ (This, [(1,[(ToReject, 1%1)])])
363 ]
364 ])
365 , testSection "1 judge, 1 choice (missing judge)"
366 [This]
367 [(1::Int,ToReject)]
368 (Node []
369 [ node0 [ (This, [(1,Section (Just $ 1%8) (Just Acceptable))])
370 ]
371 , node0 [ (This, [])
372 ]
373 ])
374 (Right $ Node
375 [ (This, [(1,[(Acceptable,1%8), (ToReject,7%8)])])
376 ]
377 [ node0 [ (This, [(1,[(Acceptable, 1%1)])])
378 ]
379 , node0 [ (This, [(1,[(ToReject, 1%1)])])
380 ]
381 ])
382 , testSection "1 judge, 1 choice (missing judge)"
383 [This]
384 [(1::Int,ToReject)]
385 (Node []
386 [ node0 [ (This, [])
387 ]
388 , node0 [ (This, [(1,Section (Just $ 1%8) (Just Acceptable))])
389 ]
390 ])
391 (Right $ Node
392 [ (This, [(1,[(Acceptable,1%8), (ToReject,7%8)])])
393 ]
394 [ node0 [ (This, [(1,[(ToReject, 1%1)])])
395 ]
396 , node0 [ (This, [(1,[(Acceptable, 1%1)])])
397 ]
398 ])
399 , testSection "1 judge, 1 choice (missing choice)"
400 [This]
401 [(1::Int,ToReject)]
402 (Node []
403 [ node0 [ (This, [(1,Section (Just $ 1%8) (Just Acceptable))])
404 ]
405 , node0 [
406 ]
407 ])
408 (Right $ Node
409 [ (This, [(1,[(Acceptable,1%8), (ToReject,7%8)])])
410 ]
411 [ node0 [ (This, [(1,[(Acceptable, 1%1)])])
412 ]
413 , node0 [ (This, [(1,[(ToReject, 1%1)])])
414 ]
415 ])
416 , testSection "1 judge, 1 choice (missing choice)"
417 [This]
418 [(1::Int,ToReject)]
419 (Node []
420 [ node0 [
421 ]
422 , node0 [ (This, [(1,Section (Just $ 1%8) (Just Acceptable))])
423 ]
424 ])
425 (Right $ Node
426 [ (This, [(1,[(Acceptable,1%8), (ToReject,7%8)])])
427 ]
428 [ node0 [ (This, [(1,[(ToReject, 1%1)])])
429 ]
430 , node0 [ (This, [(1,[(Acceptable, 1%1)])])
431 ]
432 ])
433 , testSection "2 judges, 2 choices"
434 [This, That]
435 [(1::Int,ToReject), (2::Int,ToReject)]
436 (node0
437 [ (This, [(1,Section Nothing (Just Acceptable))])
438 , (That, [(2,Section (Just $ 1%8) (Just VeryGood))])
439 ])
440 (Right $ node0
441 [ (This, [ (1,[(Acceptable,1%1)])
442 , (2,[(ToReject,1%1)])
443 ])
444 , (That, [ (1,[(ToReject,1%1)])
445 , (2,[(VeryGood,1%1)])
446 ])
447 ])
448 , testSection "2 judges, 2 choices"
449 [This, That]
450 [(1::Int,ToReject), (2::Int,ToReject)]
451 (Node
452 [ ]
453 [ node0
454 [ (This, [(1,Section Nothing (Just Good))])
455 , (That, [(2,Section Nothing (Just Insufficient))])
456 ]
457 , node0
458 [ (This, [(1,Section Nothing (Just Acceptable))])
459 , (That, [(2,Section (Just $ 1%8) (Just VeryGood))])
460 ]
461 ])
462 (Right $ Node
463 [ (This, [ (1,[(Good,1%2), (Acceptable,1%2)])
464 , (2,[(ToReject,1%1)])
465 ])
466 , (That, [ (1,[(ToReject,1%1)])
467 , (2,[(Insufficient,7%8), (VeryGood,1%8)])
468 ])
469 ]
470 [ node0 [ (This, [ (1,[(Good,1%1)])
471 , (2,[(ToReject,1%1)])
472 ])
473 , (That, [ (1,[(ToReject,1%1)])
474 , (2,[(Insufficient,1%1)])
475 ])
476 ]
477 , node0 [ (This, [ (1,[(Acceptable,1%1)])
478 , (2,[(ToReject,1%1)])
479 ])
480 , (That, [ (1,[(ToReject,1%1)])
481 , (2,[(VeryGood,1%1)])
482 ])
483 ]
484 ])
485 , testSection "2 judges, 2 choices"
486 [This, That]
487 [(1::Int,ToReject), (2::Int,ToReject)]
488 (Node [ (This, [(1,Section Nothing (Just Acceptable))])
489 ]
490 [ node0 [ (This, [(1,Section Nothing Nothing)])
491 ]
492 , node0 [ (This, [ (1,Section (Just $ 1%2) (Just Good)) ])
493 , (That, [ (1,Section (Just $ 1%3) Nothing)
494 , (2,Section (Just $ 1%5) (Just Insufficient))
495 ])
496 ]
497 , Node [ (This, [(1,Section Nothing (Just Good))])
498 , (That, [(2,Section Nothing (Just VeryGood))])
499 ]
500 [ node0 [ (This, [ (1,Section Nothing (Just VeryGood))
501 , (2,Section Nothing (Just Insufficient))
502 ])
503 , (That, [ (1,Section Nothing (Just Acceptable)) ])
504 ]
505 , node0 [ (This, [ (1,Section Nothing (Just Acceptable))
506 ])
507 , (That, [ (1,Section Nothing (Just VeryGood))
508 , (2,Section Nothing (Just Good))
509 ])
510 ]
511 ]
512 ])
513 (Right $
514 Node [ (This, [ (1,[(Acceptable,1%4 + 1%8), (Good,1%2), (VeryGood,1%8)])
515 , (2,[(ToReject,1%3 + 1%3 + 1%6), (Insufficient,1%6)])
516 ])
517 , (That, [ (1,[(ToReject,1%3 + 1%3), (Acceptable,1%6), (VeryGood,1%6)])
518 , (2,[(ToReject,4%10), (Insufficient,1%5), (VeryGood,4%20), (Good,4%20)])
519 ])
520 ]
521 [ node0 [ (This, [ (1,[(Acceptable,1%1)]) -- 1%4
522 , (2,[(ToReject,1%1)]) -- 1%3
523 ])
524 , (That, [ (1,[(ToReject,1%1)]) -- 1%3
525 , (2,[(ToReject,1%1)]) -- 4%10
526 ])
527 ]
528 , node0 [ (This, [ (1,[(Good,1%1)]) -- 1%2
529 , (2,[(ToReject,1%1)]) -- 1%3
530 ])
531 , (That, [ (1,[(ToReject,1%1)]) -- 1%3
532 , (2,[(Insufficient,1%1)]) -- 1%5
533 ])
534 ]
535 , Node [ (This, [ (1,[(VeryGood,1%2), (Acceptable,1%2)]) -- 1%4
536 , (2,[(Insufficient,1%2), (ToReject,1%2)]) -- 1%3
537 ])
538 , (That, [ (1,[(Acceptable,1%2), (VeryGood,1%2)]) -- 1%3
539 , (2,[(VeryGood,1%2), (Good,1%2)]) -- 4%10
540 ])
541 ]
542 [ node0 [ (This, [ (1,[(VeryGood,1%1)])
543 , (2,[(Insufficient,1%1)])
544 ])
545 , (That, [ (1,[(Acceptable,1%1)])
546 , (2,[(VeryGood,1%1)])
547 ])
548 ]
549 , node0 [ (This, [ (1,[(Acceptable,1%1)])
550 , (2,[(ToReject,1%1)])
551 ])
552 , (That, [ (1,[(VeryGood,1%1)])
553 , (2,[(Good,1%1)])
554 ])
555 ]
556 ]
557 ]
558 )
559 ]
560 ]
561 ]
562
563 elide :: String -> String
564 elide s | length s > 42 = take 42 s ++ ['…']
565 | otherwise = s
566
567 mkMerit :: (Ord grade, Show grade) => [grade] -> [Share] -> Merit grade
568 mkMerit gs = fromList . (gs`zip`)
569
570 mkMeritByChoice ::
571 (Eq choice, Hashable choice, Ord grade) =>
572 [(choice,[grade])] ->
573 MeritByChoice choice grade
574 mkMeritByChoice os =
575 meritByChoice $ fromList $
576 second (fromList . zip [1::Int ..] . (singleGrade <$>)) <$> os
577
578 testCompareValue :: (Ord grade, Show grade) =>
579 [(grade, Share)] -> [(grade, Share)] -> TestTree
580 testCompareValue x y =
581 testGroup (elide $ show (x,y))
582 [ testCase "x == x" $ MajorityValue x`compare`MajorityValue x @?= EQ
583 , testCase "y == y" $ MajorityValue y`compare`MajorityValue y @?= EQ
584 , testCase "x < y" $ MajorityValue x`compare`MajorityValue y @?= LT
585 , testCase "y > x" $ MajorityValue y`compare`MajorityValue x @?= GT
586 ]
587
588 testMajorityRanking ::
589 (Eq choice, Hashable choice, Ord grade, Show grade, Show choice) =>
590 [(choice, [grade])] ->
591 MajorityRanking choice grade -> TestTree
592 testMajorityRanking os expect =
593 testCase (elide $ show os) $
594 majorityRanking (mkMeritByChoice os) @?= expect
595
596 testMajorityValueOfOpinions ::
597 (Show grade, Show choice, Ord grade, Eq choice, Hashable choice) =>
598 [(choice, [grade])] ->
599 [(choice, [(grade,Share)])] -> TestTree
600 testMajorityValueOfOpinions os expect =
601 testCase (elide $ show os) $
602 majorityValueByChoice (mkMeritByChoice os)
603 @?= (MajorityValue<$>HM.fromList expect)
604
605 testMajorityValueOfMerits ::
606 (Show grade, Show choice, Ord grade, Eq choice, Hashable choice) =>
607 MeritByChoice choice grade ->
608 [(choice, [(grade,Share)])] -> TestTree
609 testMajorityValueOfMerits ms expect =
610 testCase (elide $ show ms) $
611 majorityValueByChoice ms
612 @?= (MajorityValue<$>HM.fromList expect)
613
614 testSection ::
615 Eq choice =>
616 Hashable choice =>
617 Eq judge =>
618 Hashable judge =>
619 Ord grade =>
620 Show choice =>
621 Show judge =>
622 Show grade =>
623 String ->
624 Choices choice ->
625 Judges judge grade ->
626 Tree (SectionByJudgeByChoice choice judge grade) ->
627 Either (ErrorSection choice judge grade)
628 (Tree (OpinionsByChoice choice judge grade)) ->
629 TestTree
630 testSection msg cs js ss expect =
631 testCase (elide msg) $
632 opinionsBySection cs js ss @?= expect
633
634 node0 :: a -> Tree a
635 node0 = (`Node`[])