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());
}
