Wideband autonomous SDR analysis engine forked from sdr-visual-suite
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

93 lines
2.5KB

  1. package pipeline
  2. import (
  3. "testing"
  4. "sdr-wideband-suite/internal/config"
  5. )
  6. func TestNormalizeMonitorWindows(t *testing.T) {
  7. goals := config.PipelineGoalConfig{
  8. MonitorWindows: []config.MonitorWindow{
  9. {Label: "a", StartHz: 100, EndHz: 200},
  10. {Label: "b", CenterHz: 500, SpanHz: 50},
  11. },
  12. }
  13. windows := NormalizeMonitorWindows(goals, 0)
  14. if len(windows) != 2 {
  15. t.Fatalf("expected 2 windows, got %d", len(windows))
  16. }
  17. if windows[0].StartHz != 100 || windows[0].EndHz != 200 {
  18. t.Fatalf("unexpected first window: %+v", windows[0])
  19. }
  20. if windows[1].CenterHz != 500 || windows[1].SpanHz != 50 {
  21. t.Fatalf("unexpected second window: %+v", windows[1])
  22. }
  23. }
  24. func TestMonitorWindowBounds(t *testing.T) {
  25. windows := []MonitorWindow{
  26. {StartHz: 100, EndHz: 200},
  27. {StartHz: 50, EndHz: 90},
  28. {StartHz: 500, EndHz: 800},
  29. }
  30. start, end, ok := MonitorWindowBounds(windows)
  31. if !ok {
  32. t.Fatalf("expected bounds")
  33. }
  34. if start != 50 || end != 800 {
  35. t.Fatalf("unexpected bounds: %.0f %.0f", start, end)
  36. }
  37. }
  38. func TestCandidateInMonitorWindows(t *testing.T) {
  39. policy := Policy{
  40. MonitorWindows: []MonitorWindow{
  41. {StartHz: 100, EndHz: 200},
  42. {StartHz: 300, EndHz: 400},
  43. },
  44. }
  45. if !candidateInMonitor(policy, Candidate{CenterHz: 150}) {
  46. t.Fatalf("expected candidate inside window")
  47. }
  48. if candidateInMonitor(policy, Candidate{CenterHz: 250}) {
  49. t.Fatalf("expected candidate outside windows")
  50. }
  51. }
  52. func TestMonitorWindowMatchesOverlap(t *testing.T) {
  53. policy := Policy{
  54. MonitorWindows: finalizeMonitorWindows([]MonitorWindow{
  55. {Label: "wide", StartHz: 100, EndHz: 300, SpanHz: 200},
  56. {Label: "narrow", StartHz: 150, EndHz: 220, SpanHz: 70},
  57. }),
  58. }
  59. matches := MonitorWindowMatches(policy, Candidate{CenterHz: 180, BandwidthHz: 20})
  60. if len(matches) != 2 {
  61. t.Fatalf("expected 2 matches, got %d", len(matches))
  62. }
  63. if matches[0].Index == matches[1].Index {
  64. t.Fatalf("expected distinct window matches")
  65. }
  66. }
  67. func TestMonitorWindowBiasPrefersNarrowWindow(t *testing.T) {
  68. goals := config.PipelineGoalConfig{
  69. MonitorWindows: []config.MonitorWindow{
  70. {Label: "wide", StartHz: 100, EndHz: 300},
  71. {Label: "narrow", StartHz: 150, EndHz: 200},
  72. },
  73. }
  74. policy := Policy{MonitorWindows: NormalizeMonitorWindows(goals, 0)}
  75. bias, detail := MonitorWindowBias(policy, Candidate{CenterHz: 175, BandwidthHz: 10})
  76. if detail == nil {
  77. t.Fatalf("expected monitor match detail")
  78. }
  79. if detail.Label != "narrow" {
  80. t.Fatalf("expected narrow window to be preferred, got %q", detail.Label)
  81. }
  82. if bias <= 0 {
  83. t.Fatalf("expected positive bias, got %.3f", bias)
  84. }
  85. }