use trueskill_tt::{ConstantDrift, ConvergenceOptions, History}; #[test] fn record_winner_builds_history() { let mut h = History::builder() .mu(25.0) .sigma(25.0 / 3.0) .beta(25.0 / 6.0) .drift(ConstantDrift::new(25.0 / 300.0)) .convergence(ConvergenceOptions { max_iter: 30, epsilon: 1e-6, alpha: 1.0, }) .build(); h.record_winner(&"alice", &"bob", 1).unwrap(); let _ = h.converge().unwrap(); // `lookup` returned an `Index` that nothing public accepted, so the // observable claim is the one worth making: two distinct competitors, each // with their own posterior, and the winner ahead. assert_eq!(h.competitor_count(), 2); let alice = h.current_skill("alice").expect("alice played"); let bob = h.current_skill("bob").expect("bob played"); assert!(alice.mu() > bob.mu()); } /// The same key names the same competitor across events, which is what /// interning bought and the only part of it a caller can observe. #[test] fn a_repeated_key_is_one_competitor() { let mut h: History = History::builder().build(); h.record_winner(&"alice", &"bob", 1).unwrap(); h.record_winner(&"alice", &"carol", 2).unwrap(); assert_eq!(h.competitor_count(), 3); assert_eq!(h.learning_curve("alice").expect("known").len(), 2); } #[test] fn an_unknown_key_is_unknown() { let h: History = History::builder().build(); assert!(h.current_skill("nobody").is_none()); assert!(h.learning_curve("nobody").is_none()); } #[test] fn record_draw_with_p_draw_set() { let mut h = History::builder() .mu(25.0) .sigma(25.0 / 3.0) .beta(25.0 / 6.0) .drift(ConstantDrift::new(25.0 / 300.0)) .p_draw(0.25) .build(); h.record_draw(&"alice", &"bob", 1).unwrap(); let _ = h.converge().unwrap(); assert!(h.current_skill("alice").is_some()); assert!(h.current_skill("bob").is_some()); }