Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

68 rindas
1.3KB

  1. package rds
  2. import (
  3. "math"
  4. "strings"
  5. "testing"
  6. )
  7. func TestEncoderGenerate(t *testing.T) {
  8. cfg := DefaultConfig()
  9. enc, err := NewEncoder(cfg)
  10. if err != nil {
  11. t.Fatalf("unexpected error: %v", err)
  12. }
  13. samples := enc.Generate(128)
  14. if len(samples) != 128 {
  15. t.Fatalf("expected 128 samples, got %d", len(samples))
  16. }
  17. var max float64
  18. var sum float64
  19. for _, s := range samples {
  20. sum += math.Abs(s)
  21. if math.Abs(s) > max {
  22. max = math.Abs(s)
  23. }
  24. }
  25. if sum == 0 {
  26. t.Fatalf("expected non-zero samples")
  27. }
  28. if max > 0.1 {
  29. t.Fatalf("samples exceed configured amplitude: %v", max)
  30. }
  31. }
  32. func TestEncoderReset(t *testing.T) {
  33. cfg := DefaultConfig()
  34. enc, err := NewEncoder(cfg)
  35. if err != nil {
  36. t.Fatalf("unexpected error: %v", err)
  37. }
  38. sampleA := enc.Generate(1)[0]
  39. enc.Generate(10)
  40. enc.Reset()
  41. if sampleB := enc.Generate(1)[0]; math.Abs(sampleA-sampleB) > 1e-9 {
  42. t.Fatalf("expected reset to replay initial sample: %v vs %v", sampleA, sampleB)
  43. }
  44. }
  45. func TestNormalizePS(t *testing.T) {
  46. got := normalizePS("radiox")
  47. if got != "RADIOX " {
  48. t.Fatalf("unexpected PS: %q", got)
  49. }
  50. }
  51. func TestNormalizeRT(t *testing.T) {
  52. long := strings.Repeat("a", 80)
  53. got := normalizeRT(long)
  54. if len(got) != 64 {
  55. t.Fatalf("unexpected RT length: %d", len(got))
  56. }
  57. }