77 resolve_game
88)
99
10+ class ResolutionTest :
11+ resolution : Optional [list [GameOutcome ]]
12+
13+ def __init__ (self , resolution : Optional [list [GameOutcome ]]):
14+ self .resolution = resolution
15+
16+ def __call__ (self , partial_outcomes : list [set [ArmyOutcome ]]):
17+ if self .resolution is None :
18+ with pytest .raises (GameResolutionError ):
19+ resolve_game (partial_outcomes )
20+ else :
21+ assert resolve_game (partial_outcomes ) == self .resolution
22+
23+ ResolveError = ResolutionTest (None )
24+ ResolveWin = ResolutionTest ([GameOutcome .VICTORY , GameOutcome .DEFEAT ])
25+ ResolveDraw = ResolutionTest ([GameOutcome .DRAW , GameOutcome .DRAW ])
26+ ResolveLoss = ResolutionTest ([GameOutcome .DEFEAT , GameOutcome .VICTORY ])
27+
1028
1129def test_only_rate_with_two_parties ():
1230 one_party = [{ArmyOutcome .VICTORY }]
@@ -17,21 +35,14 @@ def test_only_rate_with_two_parties():
1735 {ArmyOutcome .DEFEAT }
1836 ]
1937
20- with pytest .raises (GameResolutionError ):
21- resolve_game (one_party )
22-
23- with pytest .raises (GameResolutionError ):
24- resolve_game (three_parties )
25-
38+ ResolveError (one_party )
39+ ResolveError (three_parties )
2640 resolve_game (two_parties )
2741
2842
2943def testresolve ():
3044 team_outcomes = [{ArmyOutcome .VICTORY }, {ArmyOutcome .DEFEAT }]
31-
32- ranks = resolve_game (team_outcomes )
33-
34- assert ranks == [GameOutcome .VICTORY , GameOutcome .DEFEAT ]
45+ ResolveWin (team_outcomes )
3546
3647
3748def test_ranks_all_1v1_possibilities ():
@@ -40,95 +51,69 @@ def test_ranks_all_1v1_possibilities():
4051 With six possible outcomes there are 36 possibilities.
4152 """
4253
43- ERROR = 0
44- DRAW = 1
45- WIN = 2
46- LOSS = 3
47- # Victory Defeat Recall Draw Unknown Conflicting
48- grid = [[ERROR , WIN , WIN , WIN , WIN , WIN ] # Victory
49- [LOSS , DRAW , DRAW , ERROR , ERROR , ERROR ] # Defeat
50- [LOSS , DRAW , DRAW , ERROR , ERROR , ERROR ] # Recall
51- [LOSS , ERROR , ERROR , DRAW , ERROR , ERROR ] # Draw
52- [LOSS , ERROR , ERROR , ERROR , ERROR , ERROR ] # Unknown
53- [LOSS , ERROR , ERROR , ERROR , ERROR , ERROR ]] # Conflicting
54- outcome_list = [ArmyOutcome .VICTORY , ArmyOutcome .DEFEAT , ArmyOutcome .RECALL ,
55- ArmyOutcome .DRAW , ArmyOutcome .UNKNOWN , ArmyOutcome .CONFLICTING ]
56-
57- win_resolution = [GameOutcome .VICTORY , GameOutcome .DEFEAT ]
58- draw_resolution = [GameOutcome .DRAW , GameOutcome .DRAW ]
59- loss_resolution = [GameOutcome .DEFEAT , GameOutcome .VICTORY ]
60-
61- for outcome1 , row in grid :
62- for outcome2 , resolution in row :
54+ ERR_ = ResolveError
55+ WIN_ = ResolveWin
56+ DRAW = ResolveDraw
57+ LOSS = ResolveLoss
58+ # Victory Recall Unknown
59+ # Defeat Draw Conflicting
60+ grid = [[ERR_ , WIN_ , WIN_ , WIN_ , WIN_ , WIN_ ], # Victory
61+ [LOSS , DRAW , DRAW , ERR_ , ERR_ , ERR_ ], # Defeat
62+ [LOSS , DRAW , DRAW , ERR_ , ERR_ , ERR_ ], # Recall
63+ [LOSS , ERR_ , ERR_ , DRAW , ERR_ , ERR_ ], # Draw
64+ [LOSS , ERR_ , ERR_ , ERR_ , ERR_ , ERR_ ], # Unknown
65+ [LOSS , ERR_ , ERR_ , ERR_ , ERR_ , ERR_ ]] # Conflicting
66+ outcome_list = [o for o in ArmyOutcome ]
67+
68+ for outcome1 , row in enumerate (grid ):
69+ for outcome2 , Resolution in enumerate (row ):
6370 team_outcomes = [{outcome_list [outcome1 ]}, {outcome_list [outcome2 ]}]
64- if resolution == ERROR :
65- with pytest .raises (GameResolutionError ):
66- resolve_game (team_outcomes )
67- elif resolution == WIN :
68- assert resolve_game (team_outcomes ) == win_resolution
69- elif resolution == DRAW :
70- assert resolve_game (team_outcomes ) == draw_resolution
71- elif resolution == LOSS :
72- assert resolve_game (team_outcomes ) == loss_resolution
71+ Resolution (team_outcomes )
7372
7473
7574def test_team_outcome_ignores_unknown ():
7675 team_outcomes = [
7776 {ArmyOutcome .VICTORY , ArmyOutcome .UNKNOWN },
7877 {ArmyOutcome .DEFEAT , ArmyOutcome .UNKNOWN },
7978 ]
80-
81- ranks = resolve_game (team_outcomes )
82- assert ranks == [GameOutcome .VICTORY , GameOutcome .DEFEAT ]
79+ ResolveWin (team_outcomes )
8380
8481
8582def test_team_outcome_throws_if_unilateral_draw ():
8683 team_outcomes = [
8784 {ArmyOutcome .DRAW , ArmyOutcome .DEFEAT },
8885 {ArmyOutcome .DEFEAT , ArmyOutcome .UNKNOWN },
8986 ]
90-
91- with pytest .raises (GameResolutionError ):
92- resolve_game (team_outcomes )
87+ ResolveError (team_outcomes )
9388
9489
9590def test_team_outcome_victory_has_priority_over_defeat ():
9691 team_outcomes = [
9792 {ArmyOutcome .VICTORY , ArmyOutcome .DEFEAT },
9893 {ArmyOutcome .DEFEAT , ArmyOutcome .DEFEAT },
9994 ]
100-
101- ranks = resolve_game (team_outcomes )
102-
103- assert ranks == [GameOutcome .VICTORY , GameOutcome .DEFEAT ]
95+ ResolveWin (team_outcomes )
10496
10597
10698def test_team_outcome_victory_has_priority_over_draw ():
10799 team_outcomes = [
108100 {ArmyOutcome .VICTORY , ArmyOutcome .DRAW },
109101 {ArmyOutcome .DRAW , ArmyOutcome .DEFEAT },
110102 ]
111-
112- ranks = resolve_game (team_outcomes )
113-
114- assert ranks == [GameOutcome .VICTORY , GameOutcome .DEFEAT ]
103+ ResolveWin (team_outcomes )
115104
116105
117106def test_team_outcome_no_double_victory ():
118107 team_outcomes = [
119108 {ArmyOutcome .VICTORY , ArmyOutcome .VICTORY },
120109 {ArmyOutcome .VICTORY , ArmyOutcome .DEFEAT },
121110 ]
122-
123- with pytest .raises (GameResolutionError ):
124- resolve_game (team_outcomes )
111+ ResolveError (team_outcomes )
125112
126113
127114def test_team_outcome_unranked_if_ambiguous ():
128115 team_outcomes = [
129116 {ArmyOutcome .UNKNOWN , ArmyOutcome .DEFEAT },
130117 {ArmyOutcome .DEFEAT , ArmyOutcome .DEFEAT },
131118 ]
132-
133- with pytest .raises (GameResolutionError ):
134- resolve_game (team_outcomes )
119+ ResolveError (team_outcomes )
0 commit comments