@@ -205,20 +205,52 @@ def test_ladder_pairs():
205205
206206@pytest .mark .parametrize ("model" , MODELS )
207207@pytest .mark .parametrize ("tie_score" , [- 1 , 0 , 0.1 , 10 , 13.4 ])
208- def test_ties (model , tie_score ):
208+ @pytest .mark .parametrize ("num_teams" , [2 , 5 , 10 ])
209+ @pytest .mark .parametrize ("team_size" , [1 , 2 , 5 , 10 ])
210+ @pytest .mark .parametrize ("tie_type" , ["score" , "rank" ])
211+ def test_ties (model , tie_score , num_teams , team_size , tie_type ) -> None :
209212 model_instance = model ()
213+ teams = [
214+ [model_instance .rating () for _ in range (team_size )] for _ in range (num_teams )
215+ ]
216+ player_mu_before = [player .mu for team in teams for player in team ]
217+ assert all (
218+ mu == player_mu_before [0 ] for mu in player_mu_before
219+ ), f"Model { model .__name__ } with score { tie_score } : All players should start with equal mu"
220+
221+ player_sigma_before = [player .sigma for team in teams for player in team ]
222+ assert all (
223+ sigma == player_sigma_before [0 ] for sigma in player_sigma_before
224+ ), f"Model { model .__name__ } with score { tie_score } : All players should start with equal sigma"
225+
226+ if tie_type == "score" :
227+ scores = [tie_score for _ in range (num_teams )]
228+ new_teams = model_instance .rate (teams , scores = scores )
229+ else : # rank
230+ ranks = [tie_score for _ in range (num_teams )]
231+ new_teams = model_instance .rate (teams , ranks = ranks )
232+
233+ player_mu_after = [player .mu for team in new_teams for player in team ]
234+ assert all (
235+ mu_after == mu_before
236+ for mu_after , mu_before in zip (player_mu_after , player_mu_before )
237+ ), f"Model { model .__name__ } with score { tie_score } : All players should end with equal mu"
238+ player_sigma_after = [player .sigma for team in new_teams for player in team ]
239+ assert all (
240+ sigma_after <= sigma_before
241+ for sigma_after , sigma_before in zip (player_sigma_after , player_sigma_before )
242+ ), f"Model { model .__name__ } with score { tie_score } : All players should end with lower or equal sigma"
210243
211- player_1 = model_instance .rating ()
212- player_2 = model_instance .rating ()
213244
214- result = model_instance .rate (
215- [[player_1 ], [player_2 ]], scores = [tie_score , tie_score ]
216- )
245+ @pytest .mark .parametrize ("model" , MODELS )
246+ def test_ties_with_close_ratings (model ) -> None :
247+ model_instance = model ()
248+
249+ player_1 = model_instance .rating (mu = 30 )
250+ player_2 = model_instance .rating (mu = 20 )
251+
252+ new_teams = model_instance .rate ([[player_1 ], [player_2 ]], ranks = [0 , 0 ])
217253
218- # Both players should have the same rating change
219- assert (
220- result [0 ][0 ].mu == result [1 ][0 ].mu
221- ), f"Model { model .__name__ } with score { tie_score } : Players should have equal mu after tie"
222- assert (
223- result [0 ][0 ].sigma == result [1 ][0 ].sigma
224- ), f"Model { model .__name__ } with score { tie_score } : Players should have equal sigma after tie"
254+ # ratings should converge on ties.
255+ assert new_teams [0 ][0 ].mu < 30
256+ assert new_teams [1 ][0 ].mu > 20
0 commit comments