From 77523e9db4e2e5e9e66ac5975354cd0667dedd97 Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Wed, 24 Oct 2018 18:02:11 +0200 Subject: [PATCH] Added test for draw. --- src/lib.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5207ac2..72d3f91 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(rating_groups: &[&[R]]) -> Vec +pub fn rate(rating_groups: &[&[R]], ranks: &[u16]) -> Vec 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); + } + } + }