//! Tests for diagnostic metrics

use mecha10_diagnostics::metrics::{Counter, Gauge, Histogram};

#[test]
fn test_counter() {
    let counter = Counter::new();
    assert_eq!(counter.get(), 0);

    counter.inc();
    assert_eq!(counter.get(), 1);

    counter.add(5);
    assert_eq!(counter.get(), 6);

    counter.reset();
    assert_eq!(counter.get(), 0);
}

#[test]
fn test_gauge() {
    let gauge = Gauge::new();
    assert_eq!(gauge.get(), 0);

    gauge.set(10);
    assert_eq!(gauge.get(), 10);

    gauge.inc();
    assert_eq!(gauge.get(), 11);

    gauge.dec();
    assert_eq!(gauge.get(), 10);

    gauge.add(5);
    assert_eq!(gauge.get(), 15);

    gauge.sub(3);
    assert_eq!(gauge.get(), 12);
}

#[test]
fn test_histogram() {
    let mut hist = Histogram::for_duration().unwrap();

    // Record some values (microseconds)
    for _ in 0..100 {
        hist.record(1000); // 1ms
    }
    for _ in 0..100 {
        hist.record(5000); // 5ms
    }
    for _ in 0..10 {
        hist.record(50000); // 50ms
    }

    assert_eq!(hist.count(), 210);
    assert!(hist.mean() > 1000.0);
    assert!(hist.p95() >= 5000);
}
