Wideband autonomous SDR analysis engine forked from sdr-visual-suite
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

64 строки
2.2KB

  1. package pipeline
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. func TestHoldPolicyArchiveBiasesRecord(t *testing.T) {
  7. policy := Policy{DecisionHoldMs: 1000, Profile: "archive", RefinementStrategy: "archive-oriented"}
  8. hold := HoldPolicyFromPolicy(policy)
  9. if hold.RecordMs <= hold.BaseMs {
  10. t.Fatalf("expected archive profile to extend record hold, got %d vs %d", hold.RecordMs, hold.BaseMs)
  11. }
  12. if hold.RefinementMs <= hold.BaseMs {
  13. t.Fatalf("expected archive profile to extend refinement hold, got %d vs %d", hold.RefinementMs, hold.BaseMs)
  14. }
  15. if !containsReason(hold.Reasons, HoldReasonProfileArchive) {
  16. t.Fatalf("expected profile archive reason, got %+v", hold.Reasons)
  17. }
  18. }
  19. func TestHoldPolicyDigitalBiasesDecode(t *testing.T) {
  20. policy := Policy{DecisionHoldMs: 1000, Profile: "digital-hunting", RefinementStrategy: "digital-hunting"}
  21. hold := HoldPolicyFromPolicy(policy)
  22. if hold.DecodeMs <= hold.RecordMs {
  23. t.Fatalf("expected digital profile to favor decode hold, got decode=%d record=%d", hold.DecodeMs, hold.RecordMs)
  24. }
  25. if !containsReason(hold.Reasons, HoldReasonProfileDigital) {
  26. t.Fatalf("expected profile digital reason, got %+v", hold.Reasons)
  27. }
  28. }
  29. func TestAdmitRefinementPlanNoCandidatesReason(t *testing.T) {
  30. res := AdmitRefinementPlan(RefinementPlan{}, Policy{}, time.Now(), &RefinementHold{Active: map[int64]time.Time{}})
  31. if res.Admission.Reason != ReasonAdmissionNoCandidates {
  32. t.Fatalf("expected no-candidates reason, got %s", res.Admission.Reason)
  33. }
  34. }
  35. func TestAdmitRefinementPlanUnlimitedBudget(t *testing.T) {
  36. policy := Policy{MaxRefinementJobs: 0, MinCandidateSNRDb: 0}
  37. cands := []Candidate{
  38. {ID: 1, CenterHz: 100, SNRDb: 5},
  39. {ID: 2, CenterHz: 200, SNRDb: 6},
  40. }
  41. plan := BuildRefinementPlan(cands, policy)
  42. res := AdmitRefinementPlan(plan, policy, time.Now(), &RefinementHold{Active: map[int64]time.Time{}})
  43. if len(res.Plan.Selected) != len(cands) {
  44. t.Fatalf("expected all candidates admitted, got %d", len(res.Plan.Selected))
  45. }
  46. if res.Admission.Skipped != 0 || res.Plan.DroppedByBudget != 0 {
  47. t.Fatalf("expected no budget drops, got admission=%+v plan=%+v", res.Admission, res.Plan)
  48. }
  49. }
  50. func containsReason(reasons []string, target string) bool {
  51. for _, r := range reasons {
  52. if r == target {
  53. return true
  54. }
  55. }
  56. return false
  57. }