Added test for draw.

This commit is contained in:
2018-10-24 18:02:11 +02:00
parent b0d6076a67
commit 77523e9db4

View File

@@ -72,7 +72,7 @@ fn draw_margin(p: f64, beta: f64, total_players: f64) -> f64 {
math::icdf((p + 1.0) / 2.0) * total_players.sqrt() * beta
}
pub fn rate<R>(rating_groups: &[&[R]]) -> Vec<Rating>
pub fn rate<R>(rating_groups: &[&[R]], ranks: &[u16]) -> Vec<Rating>
where
R: Rateable,
{
@@ -174,7 +174,7 @@ where
factor_id,
ds[i],
epsilon,
false,
ranks[i] == ranks[i + 1],
));
factor_id += 1;
@@ -342,7 +342,7 @@ mod tests {
}
#[test]
fn test_rate_1vs1() {
fn test_rate_4vs4() {
let alice = Rating::new(MU, SIGMA);
let bob = Rating::new(MU, SIGMA);
let chris = Rating::new(MU, SIGMA);
@@ -355,10 +355,28 @@ mod tests {
Rating::new(16.79337409436942, 6.348053083319977),
];
let ratings = rate(&[&[alice], &[bob], &[chris], &[darren]]);
let ratings = rate(&[&[alice], &[bob], &[chris], &[darren]], &[0, 1, 2, 3]);
for (rating, expected) in ratings.iter().zip(expected_ratings.iter()) {
assert_relative_eq!(rating, expected, epsilon = EPSILON);
}
}
#[test]
fn test_rate_1vs1_draw() {
let alice = Rating::new(MU, SIGMA);
let bob = Rating::new(MU, SIGMA);
let expected_ratings = vec![
Rating::new(25.0, 6.457515683245051),
Rating::new(25.0, 6.457515683245051),
];
let ratings = rate(&[&[alice], &[bob]], &[0, 0]);
for (rating, expected) in ratings.iter().zip(expected_ratings.iter()) {
assert_relative_eq!(rating, expected, epsilon = EPSILON);
}
}
}