Initial commit.

This commit is contained in:
2018-10-13 11:40:03 +02:00
commit 583c0f8ce6
3 changed files with 36 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
/target
**/*.rs.bk
Cargo.lock

6
Cargo.toml Normal file
View File

@@ -0,0 +1,6 @@
[package]
name = "elo"
version = "0.1.0"
authors = ["Anders Olsson <anders.e.olsson@gmail.com>"]
[dependencies]

27
src/lib.rs Normal file
View File

@@ -0,0 +1,27 @@
pub fn rating(a: f32, b: f32, score: f32, n: f32, k: f32) -> f32 {
a + delta(score, expected(a, b, n), k)
}
fn delta(score: f32, rating: f32, k: f32) -> f32 {
k * (score - rating)
}
fn expected(a: f32, b: f32, n: f32) -> f32 {
1.0 / (1.0 + 10.0_f32.powf((b - a) / n))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_rating() {
let r = rating(1600.0, 1600.0, 1.0, 400.0, 32.0);
assert_eq!(r, 1616.0);
let r = rating(1600.0, 1600.0, 0.5, 400.0, 32.0);
assert_eq!(r, 1600.0);
}
}