2017-11-15 09:32:39 +00:00
|
|
|
defmodule Glicko.PlayerTest do
|
2020-01-19 13:58:40 +00:00
|
|
|
use ExUnit.Case
|
2017-11-15 09:32:39 +00:00
|
|
|
|
2020-01-19 13:58:40 +00:00
|
|
|
alias Glicko.Player
|
2017-11-15 09:32:39 +00:00
|
|
|
|
2020-01-19 13:58:40 +00:00
|
|
|
doctest Player
|
2017-11-15 09:32:39 +00:00
|
|
|
|
2020-02-05 04:15:20 +00:00
|
|
|
@valid_v1_base %Player.V1{rating: 1.0, rating_deviation: 2.0}
|
|
|
|
@valid_v2_base %Player.V2{rating: 1.0, rating_deviation: 2.0, volatility: 3.0}
|
2017-11-15 09:32:39 +00:00
|
|
|
|
2020-01-19 13:58:40 +00:00
|
|
|
test "create v1" do
|
|
|
|
assert @valid_v1_base == Player.new_v1(rating: 1.0, rating_deviation: 2.0)
|
|
|
|
end
|
2017-11-15 09:32:39 +00:00
|
|
|
|
2020-01-19 13:58:40 +00:00
|
|
|
test "create v2" do
|
|
|
|
assert @valid_v2_base == Player.new_v2(rating: 1.0, rating_deviation: 2.0, volatility: 3.0)
|
|
|
|
end
|
2017-11-15 09:32:39 +00:00
|
|
|
|
2020-01-19 13:58:40 +00:00
|
|
|
test "convert player v1 -> v2" do
|
2020-02-05 04:15:20 +00:00
|
|
|
assert Player.new_v2(
|
|
|
|
rating: Player.scale_rating_to(1.0, :v2),
|
|
|
|
rating_deviation: Player.scale_rating_deviation_to(2.0, :v2),
|
|
|
|
volatility: 3.0
|
|
|
|
) == Player.to_v2(@valid_v1_base, 3.0)
|
2020-01-19 13:58:40 +00:00
|
|
|
end
|
2017-11-15 09:32:39 +00:00
|
|
|
|
2020-01-19 13:58:40 +00:00
|
|
|
test "convert player v2 -> v1" do
|
2020-02-05 04:15:20 +00:00
|
|
|
assert Player.new_v1(
|
|
|
|
rating: Player.scale_rating_to(1.0, :v1),
|
|
|
|
rating_deviation: Player.scale_rating_deviation_to(2.0, :v1)
|
|
|
|
) == Player.to_v1(@valid_v2_base)
|
2020-01-19 13:58:40 +00:00
|
|
|
end
|
2017-11-15 09:32:39 +00:00
|
|
|
|
2020-01-19 13:58:40 +00:00
|
|
|
test "convert player v1 -> v1" do
|
|
|
|
assert @valid_v1_base == Player.to_v1(@valid_v1_base)
|
|
|
|
end
|
2017-11-15 09:32:39 +00:00
|
|
|
|
2020-01-19 13:58:40 +00:00
|
|
|
test "convert player v2 -> v2" do
|
|
|
|
assert @valid_v2_base == Player.to_v2(@valid_v2_base)
|
|
|
|
end
|
2017-11-15 09:32:39 +00:00
|
|
|
|
2020-01-19 13:58:40 +00:00
|
|
|
test "scale rating v1 -> v2" do
|
|
|
|
assert_in_delta Player.scale_rating_to(1673.7178, :v2), 1.0, 0.1
|
|
|
|
end
|
2017-11-15 09:32:39 +00:00
|
|
|
|
2020-01-19 13:58:40 +00:00
|
|
|
test "scale rating v2 -> v1" do
|
|
|
|
assert_in_delta Player.scale_rating_to(1.0, :v1), 1673.7178, 0.1
|
|
|
|
end
|
2017-11-15 09:32:39 +00:00
|
|
|
|
2020-01-19 13:58:40 +00:00
|
|
|
test "scale rating deviation v1 -> v2" do
|
|
|
|
assert_in_delta Player.scale_rating_deviation_to(173.7178, :v2), 1.0, 0.1
|
|
|
|
end
|
2017-11-15 09:32:39 +00:00
|
|
|
|
2020-01-19 13:58:40 +00:00
|
|
|
test "scale rating deviation v2 -> v1" do
|
|
|
|
assert_in_delta Player.scale_rating_deviation_to(1.0, :v1), 173.7178, 0.1
|
|
|
|
end
|
2017-11-15 12:32:47 +00:00
|
|
|
|
2020-01-19 13:58:40 +00:00
|
|
|
test "rating interval" do
|
|
|
|
assert {rating_low, rating_high} =
|
|
|
|
[rating: 1850, rating_deviation: 50]
|
|
|
|
|> Player.new_v2()
|
|
|
|
|> Player.rating_interval()
|
2017-11-15 12:32:47 +00:00
|
|
|
|
2020-01-19 13:58:40 +00:00
|
|
|
assert_in_delta rating_low, 1750, 0.1
|
|
|
|
assert_in_delta rating_high, 1950, 0.1
|
|
|
|
end
|
2017-11-15 09:32:39 +00:00
|
|
|
end
|