using Test, Random
include(joinpath(@__DIR__, "..", "src", "MM1.jl"))
using .MM1

@testset "M/M/1 waiting time against theory" begin
    λ, μ = 0.8, 1.0
    theory = λ / (μ * (μ - λ))      # Wq = ρ / (μ - λ) = 4
    rng = Xoshiro(2026)
    x = [mean_wait(λ, μ, 100_000; rng) for _ in 1:30]
    m, h = confidence_interval(x; z = 3)
    println("simulated: ", round(m; digits = 3), " ± ", round(h; digits = 3), ", theory: ", round(theory; digits = 3))
    @test allunique(x)              # the replications must differ
    @test abs(m - theory) < h
end

@testset "Unstable queue is rejected" begin
    @test_throws ArgumentError mean_wait(1.0, 1.0, 10)
    @test_throws ArgumentError mean_wait(1.2, 1.0, 10)
end
