0705986929
Game and OwnedGame gain a convergence: ConvergenceOptions field set at
construction. Game::{ranked,scored} forward options.convergence into
OwnedGame::{new,new_scored} (previously dropped on the floor).
{ranked,scored}_with_arena take it as a parameter. run_chain reads
self.convergence.{epsilon, max_iter, alpha} instead of hardcoded
1e-6 / 10 / undamped. DiffFactor::propagate gains an alpha parameter
and dispatches into Trunc/MarginFactor::propagate_with_alpha.
In-tree callsites in src/time_slice.rs and src/history.rs pass
ConvergenceOptions::default(). Pre-existing T2 fallout in tests,
benches, and the atp example (struct literals missing the new alpha
field) is fixed by adding alpha: 1.0 so the workspace builds clean.
Default alpha is 1.0, so all 96 lib + 27 integration test goldens
remain bit-equal.
56 lines
1.3 KiB
Rust
56 lines
1.3 KiB
Rust
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(25.0 / 300.0))
|
|
.convergence(ConvergenceOptions {
|
|
max_iter: 30,
|
|
epsilon: 1e-6,
|
|
alpha: 1.0,
|
|
})
|
|
.build();
|
|
|
|
h.record_winner(&"alice", &"bob", 1).unwrap();
|
|
h.converge().unwrap();
|
|
|
|
let a_idx = h.lookup(&"alice").unwrap();
|
|
let b_idx = h.lookup(&"bob").unwrap();
|
|
|
|
assert_ne!(a_idx, b_idx);
|
|
}
|
|
|
|
#[test]
|
|
fn intern_is_idempotent() {
|
|
let mut h: History = History::builder().build();
|
|
let a1 = h.intern(&"alice");
|
|
let a2 = h.intern(&"alice");
|
|
assert_eq!(a1, a2);
|
|
}
|
|
|
|
#[test]
|
|
fn lookup_returns_none_for_missing() {
|
|
let h: History = History::builder().build();
|
|
assert!(h.lookup(&"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(25.0 / 300.0))
|
|
.p_draw(0.25)
|
|
.build();
|
|
|
|
h.record_draw(&"alice", &"bob", 1).unwrap();
|
|
h.converge().unwrap();
|
|
|
|
assert!(h.lookup(&"alice").is_some());
|
|
assert!(h.lookup(&"bob").is_some());
|
|
}
|