You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
3.5 KiB
133 lines
3.5 KiB
require "rank_king/open_skill"
|
|
|
|
include RankKing
|
|
|
|
class TestRate < Minitest::Test
|
|
def setup
|
|
@os = OpenSkill.new(tau: 0)
|
|
@a1 = @os.rating(mu: 29.182, sigma: 4.782)
|
|
@b1 = @os.rating(mu: 27.174, sigma: 4.922)
|
|
@c1 = @os.rating(mu: 16.672, sigma: 6.217)
|
|
@d1 = @os.rating
|
|
@e1 = @os.rating
|
|
@f1 = @os.rating
|
|
@w1 = @os.rating(mu: 15)
|
|
@x1 = @os.rating(mu: 20)
|
|
@y1 = @os.rating(mu: 25)
|
|
@z1 = @os.rating(mu: 30)
|
|
end
|
|
|
|
def test_rate
|
|
a2, b2, c2, d2 = @os.rate([[@a1], [@b1], [@c1], [@d1]]).flatten
|
|
|
|
assert_rating a2, OpenSkill::Rating.new(mu: 30.209971908310553, sigma: 4.764898977359521)
|
|
assert_rating b2, OpenSkill::Rating.new(mu: 27.64460833689499, sigma: 4.882789305097372)
|
|
assert_rating c2, OpenSkill::Rating.new(mu: 17.403586731283518, sigma: 6.100723440599442)
|
|
assert_rating d2, OpenSkill::Rating.new(mu: 19.214790707434826, sigma: 7.8542613981643985)
|
|
end
|
|
|
|
def test_tau
|
|
# TODO
|
|
end
|
|
|
|
private
|
|
|
|
def assert_rating(expected, actual)
|
|
assert_in_delta expected.mu, actual.mu, 0.0001, "Expected #{actual} to equal #{expected}"
|
|
assert_in_delta expected.sigma, actual.sigma, 0.0001, "Expected #{actual} to equal #{expected}"
|
|
end
|
|
end
|
|
|
|
class TestRating < Minitest::Test
|
|
def test_initialize_rating
|
|
rating = OpenSkill.new.rating(mu: 12, sigma: 34)
|
|
assert_in_delta 12, rating.mu
|
|
assert_in_delta 34, rating.sigma
|
|
|
|
rating = OpenSkill.new.rating(mu: 42)
|
|
assert_in_delta 42, rating.mu
|
|
assert_in_delta 14, rating.sigma
|
|
|
|
rating = OpenSkill.new.rating(sigma: 6.283185)
|
|
assert_in_delta 25, rating.mu
|
|
assert_in_delta 6.283185, rating.sigma
|
|
|
|
rating = OpenSkill.new.rating(sigma: 0)
|
|
assert_in_delta 25, rating.mu
|
|
assert_in_delta 0, rating.sigma
|
|
end
|
|
|
|
def test_ordinal
|
|
assert_in_delta (-1), OpenSkill::Rating.new(mu: 5, sigma: 2).ordinal
|
|
end
|
|
end
|
|
|
|
class TestUtils < Minitest::Test
|
|
def setup
|
|
@os = OpenSkill.new
|
|
@r = @os.rating
|
|
end
|
|
|
|
def test_team_ratings
|
|
# TODO
|
|
end
|
|
|
|
def test_utils
|
|
team_1 = [@r]
|
|
team_2 = [@r, @r]
|
|
team_ratings = @os.team_ratings([team_1, team_2])
|
|
|
|
c = @os.util_c(team_ratings)
|
|
assert_in_delta 15.590239, c
|
|
|
|
sum_q = @os.util_sum_q(team_ratings, c)
|
|
[29.67892702634643, 24.70819334370875].zip(sum_q).each do |actual, expected|
|
|
assert_in_delta actual, expected
|
|
end
|
|
end
|
|
|
|
def test_utils_5v5
|
|
team = Array.new(5) { @r }
|
|
team_ratings = @os.team_ratings([team, team])
|
|
|
|
c = @os.util_c(team_ratings)
|
|
assert_in_delta 27.003, c
|
|
|
|
sum_q = @os.util_sum_q(team_ratings, c)
|
|
[204.84, 102.42].zip(sum_q).each do |actual, expected|
|
|
assert_in_delta actual, expected, 0.01
|
|
end
|
|
end
|
|
|
|
def test_util_a
|
|
team = [@r]
|
|
team_ratings = @os.team_ratings([team, team, team, team])
|
|
.zip([1, 1, 1, 4])
|
|
.map { _1.with(rank: _2) }
|
|
|
|
a = @os.util_a(team_ratings)
|
|
|
|
assert_equal [3, 3, 3, 1], a
|
|
end
|
|
end
|
|
|
|
class TestUnwind < Minitest::Test
|
|
def test_unwind
|
|
assert_equal [[], []], OpenSkill.unwind([], [])
|
|
assert_equal [%w[a], [0]], OpenSkill.unwind(%w[a], [0])
|
|
assert_equal [%w[a b], [1, 0]], OpenSkill.unwind(%w[b a], [1, 0])
|
|
assert_equal [%w[b c a], [1, 2, 0]], OpenSkill.unwind(%w[a b c], [2, 0, 1])
|
|
assert_equal [%w[b d c a], [1, 3, 2, 0]], OpenSkill.unwind(%w[a b c d], [3, 0, 2, 1])
|
|
end
|
|
|
|
def test_reverse
|
|
src = (?a..?z).to_a.shuffle
|
|
rank = (0..25).to_a.shuffle
|
|
trans, derank = OpenSkill.unwind(src, rank)
|
|
dst, dederank = OpenSkill.unwind(trans, derank)
|
|
|
|
assert_equal src, dst
|
|
refute_same rank, dederank
|
|
end
|
|
end
|