import { test } from "bun:test"
import { equal as assertEqual, ok as assert } from "assert"
import { rng, randomIndex } from "../src/shared/utils"

test("randomIndex", () => {
  let idx = randomIndex([5, 7, 9])!
  assert(idx >= 0 && idx < 3)

  idx = randomIndex([5])!
  assertEqual(idx, 0)
})

test("rng", () => {
  assertEqual(rng(0, 0), 0)

  const samples = Array.from({ length: 1000 }, () => rng(0, 1))
  const avg = samples.reduce((a, b) => a + b, 0) / samples.length
  assert(avg > 0.45 && avg < 0.55, "Average not close to 0.5")
})

