package dsp

import (
	"math"
	"testing"
)

func TestGoertzelDetectsTone(t *testing.T) {
	fs := 228000.0
	n := 22800 // 100ms
	freq := 19000.0
	samples := make([]float64, n)
	for i := range samples {
		samples[i] = math.Sin(2 * math.Pi * freq * float64(i) / fs)
	}
	energy := GoertzelEnergy(samples, fs, freq)
	noiseEnergy := GoertzelEnergy(samples, fs, 5000)
	if energy < noiseEnergy*100 {
		t.Fatalf("expected strong energy at %.0f Hz: got %.4f vs noise %.4f", freq, energy, noiseEnergy)
	}
}

func TestGoertzelSilence(t *testing.T) {
	samples := make([]float64, 1000)
	if GoertzelEnergy(samples, 228000, 19000) > 1e-12 {
		t.Fatal("expected near-zero energy for silence")
	}
}
