24 lines
998 B
Python
24 lines
998 B
Python
from typing import Iterable
|
|
|
|
from app.elo import rerank
|
|
|
|
|
|
def test():
|
|
# From https://github.com/sublee/elo/blob/master/elotests.py
|
|
assert _almost_equal(rerank([1200, 800], [1]), [1190.909, 809.091])
|
|
# Couldn't find any test-cases for multiplayer games, so I made this by-hand.
|
|
# The logic I chose for ELO calculation in the face of multiple possible winners has the nice property that a
|
|
# player's outcome score is independent of any other player's outcome - if you win, you get the same ELO score
|
|
# whether "you beat everyone else" or "everybody won". So I could calculate the expected scores by running `rerank`
|
|
# in the single-victory case.
|
|
assert _almost_equal(rerank([1200, 800, 500], [0, 2]), [1203.694, 796.866, 509.438])
|
|
|
|
|
|
def _almost_equal(actual: Iterable, expected: Iterable) -> bool:
|
|
assert len(actual) == len(expected)
|
|
for f, s in zip(actual, expected):
|
|
if (s - f) > (0.00001 * f):
|
|
return False
|
|
else:
|
|
return True
|