|
- package runtime
-
- import (
- "testing"
-
- "sdr-visual-suite/internal/config"
- )
-
- func TestApplyConfigUpdate(t *testing.T) {
- cfg := config.Default()
- mgr := New(cfg)
-
- center := 7.2e6
- sampleRate := 1_024_000
- fftSize := 4096
- threshold := -35.0
- bw := 1536
- cfarEnabled := true
- cfarGuard := 2
- cfarTrain := 12
- cfarRank := 18
- cfarScale := 5.5
-
- updated, err := mgr.ApplyConfig(ConfigUpdate{
- CenterHz: ¢er,
- SampleRate: &sampleRate,
- FFTSize: &fftSize,
- TunerBwKHz: &bw,
- Detector: &DetectorUpdate{
- ThresholdDb: &threshold,
- CFAREnabled: &cfarEnabled,
- CFARGuardCells: &cfarGuard,
- CFARTrainCells: &cfarTrain,
- CFARRank: &cfarRank,
- CFARScaleDb: &cfarScale,
- },
- })
- if err != nil {
- t.Fatalf("apply: %v", err)
- }
- if updated.CenterHz != center {
- t.Fatalf("center hz: %v", updated.CenterHz)
- }
- if updated.SampleRate != sampleRate {
- t.Fatalf("sample rate: %v", updated.SampleRate)
- }
- if updated.FFTSize != fftSize {
- t.Fatalf("fft size: %v", updated.FFTSize)
- }
- if updated.Detector.ThresholdDb != threshold {
- t.Fatalf("threshold: %v", updated.Detector.ThresholdDb)
- }
- if updated.Detector.CFAREnabled != cfarEnabled {
- t.Fatalf("cfar enabled: %v", updated.Detector.CFAREnabled)
- }
- if updated.Detector.CFARGuardCells != cfarGuard {
- t.Fatalf("cfar guard: %v", updated.Detector.CFARGuardCells)
- }
- if updated.Detector.CFARTrainCells != cfarTrain {
- t.Fatalf("cfar train: %v", updated.Detector.CFARTrainCells)
- }
- if updated.Detector.CFARRank != cfarRank {
- t.Fatalf("cfar rank: %v", updated.Detector.CFARRank)
- }
- if updated.Detector.CFARScaleDb != cfarScale {
- t.Fatalf("cfar scale: %v", updated.Detector.CFARScaleDb)
- }
- if updated.TunerBwKHz != bw {
- t.Fatalf("tuner bw: %v", updated.TunerBwKHz)
- }
- }
-
- func TestApplyConfigRejectsInvalid(t *testing.T) {
- cfg := config.Default()
- mgr := New(cfg)
- bad := 0
- if _, err := mgr.ApplyConfig(ConfigUpdate{SampleRate: &bad}); err == nil {
- t.Fatalf("expected error")
- }
- snap := mgr.Snapshot()
- if snap.SampleRate != cfg.SampleRate {
- t.Fatalf("sample rate changed on error")
- }
- }
-
- func TestApplySettings(t *testing.T) {
- cfg := config.Default()
- mgr := New(cfg)
- agc := true
- dc := true
- iq := true
- updated, err := mgr.ApplySettings(SettingsUpdate{
- AGC: &agc,
- DCBlock: &dc,
- IQBalance: &iq,
- })
- if err != nil {
- t.Fatalf("apply settings: %v", err)
- }
- if !updated.AGC || !updated.DCBlock || !updated.IQBalance {
- t.Fatalf("settings not applied: %+v", updated)
- }
- }
|