2017-11-16 01:39:07 +00:00
|
|
|
defmodule GlickoTest do
|
|
|
|
use ExUnit.Case
|
|
|
|
|
|
|
|
alias Glicko.{
|
|
|
|
Player,
|
2017-11-16 11:44:01 +00:00
|
|
|
Result,
|
2017-11-16 01:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doctest Glicko
|
|
|
|
|
2017-11-29 01:11:35 +00:00
|
|
|
@player [rating: 1500, rating_deviation: 200] |> Player.new_v1 |> Player.to_v2
|
2017-11-16 01:39:07 +00:00
|
|
|
|
|
|
|
@results [
|
2017-11-17 00:08:25 +00:00
|
|
|
Result.new(Player.new_v1([rating: 1400, rating_deviation: 30]), :win),
|
|
|
|
Result.new(Player.new_v1([rating: 1550, rating_deviation: 100]), :loss),
|
2017-11-16 11:44:01 +00:00
|
|
|
Result.new(Player.new_v1([rating: 1700, rating_deviation: 300]), :loss),
|
2017-11-16 01:39:07 +00:00
|
|
|
]
|
|
|
|
|
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
|
|
|
|
2017-11-16 03:19:44 +00:00
|
|
|
@valid_player_rating_deviation_after_no_results 200.2714 |> Player.scale_rating_deviation_to(:v2)
|
|
|
|
|
|
|
|
test "new rating (with results)" do
|
2017-11-17 00:08:25 +00:00
|
|
|
player = Glicko.new_rating(@player, @results, [system_constant: 0.5])
|
2017-11-16 01:39:07 +00:00
|
|
|
|
2017-11-17 00:08:25 +00:00
|
|
|
assert_in_delta Player.rating(player), @valid_player_rating_after_results, 1.0e-4
|
|
|
|
assert_in_delta Player.rating_deviation(player), @valid_player_rating_deviation_after_results, 1.0e-4
|
|
|
|
assert_in_delta Player.volatility(player), @valid_player_volatility_after_results, 1.0e-5
|
2017-11-16 01:39:07 +00:00
|
|
|
end
|
2017-11-16 03:19:44 +00:00
|
|
|
|
|
|
|
test "new rating (no results)" do
|
2017-11-17 00:08:25 +00:00
|
|
|
player = Glicko.new_rating(@player, [])
|
2017-11-16 03:19:44 +00:00
|
|
|
|
2017-11-17 00:08:25 +00:00
|
|
|
assert_in_delta Player.rating_deviation(player), @valid_player_rating_deviation_after_no_results, 1.0e-4
|
2017-11-16 03:19:44 +00:00
|
|
|
end
|
2017-11-29 02:10:02 +00:00
|
|
|
|
|
|
|
test "win probability with same ratings" do
|
|
|
|
assert Glicko.win_probability(Player.new_v1, Player.new_v1) == 0.5
|
|
|
|
end
|
|
|
|
|
|
|
|
test "win probability with better opponent" do
|
|
|
|
assert Glicko.win_probability(Player.new_v1([rating: 1500]), Player.new_v1([rating: 1600])) < 0.5
|
|
|
|
end
|
|
|
|
|
|
|
|
test "win probability with better player" do
|
|
|
|
assert Glicko.win_probability(Player.new_v1([rating: 1600]), Player.new_v1([rating: 1500])) > 0.5
|
|
|
|
end
|
2017-11-16 01:39:07 +00:00
|
|
|
end
|