2017-11-16 01:39:07 +00:00
|
|
|
defmodule GlickoTest do
|
|
|
|
use ExUnit.Case
|
|
|
|
|
|
|
|
alias Glicko.{
|
|
|
|
Player,
|
|
|
|
GameResult,
|
|
|
|
}
|
|
|
|
|
|
|
|
doctest Glicko
|
|
|
|
|
2017-11-16 02:37:56 +00:00
|
|
|
@player Player.new_v1([rating: 1500, rating_deviation: 200]) |> Player.to_v2
|
2017-11-16 01:39:07 +00:00
|
|
|
|
|
|
|
@results [
|
|
|
|
GameResult.new(Player.new_v1([rating: 1400, rating_deviation: 30]), :win),
|
|
|
|
GameResult.new(Player.new_v1([rating: 1550, rating_deviation: 100]), :loss),
|
|
|
|
GameResult.new(Player.new_v1([rating: 1700, rating_deviation: 300]), :loss),
|
|
|
|
]
|
|
|
|
|
2017-11-16 02:37:56 +00:00
|
|
|
@valid_player_rating_after_results 1464.06 |> Player.scale_rating_to(:v2)
|
|
|
|
@valid_player_rating_deviation_after_results 151.52 |> Player.scale_rating_deviation_to(:v2)
|
|
|
|
@valid_player_volatility_after_results 0.05999
|
2017-11-16 01:39:07 +00:00
|
|
|
|
|
|
|
test "new rating" do
|
2017-11-16 02:37:56 +00:00
|
|
|
%Player{rating: new_rating, rating_deviation: new_rating_deviation, volatility: new_volatility} =
|
|
|
|
Glicko.new_rating(@player, @results, [system_constant: 0.5])
|
2017-11-16 01:39:07 +00:00
|
|
|
|
2017-11-16 02:37:56 +00:00
|
|
|
assert_in_delta new_rating, @valid_player_rating_after_results, 1.0e-4
|
|
|
|
assert_in_delta new_rating_deviation, @valid_player_rating_deviation_after_results, 1.0e-4
|
|
|
|
assert_in_delta new_volatility, @valid_player_volatility_after_results, 1.0e-5
|
2017-11-16 01:39:07 +00:00
|
|
|
end
|
|
|
|
end
|