Wideband autonomous SDR analysis engine forked from sdr-visual-suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6KB

  1. package recorder
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. func TestRingSampleCapacityPartialTrim(t *testing.T) {
  7. r := NewRing(10, 2, 2) // 20 samples capacity
  8. base := time.Unix(1700000000, 0)
  9. push := func(start int, n int, t0 time.Time) {
  10. s := make([]complex64, n)
  11. for i := range s {
  12. s[i] = complex(float32(start+i), 0)
  13. }
  14. r.Push(t0, s)
  15. }
  16. push(0, 8, base)
  17. push(8, 8, base.Add(800*time.Millisecond))
  18. push(16, 8, base.Add(1600*time.Millisecond))
  19. out := r.Slice(base, base.Add(4*time.Second))
  20. if got, want := len(out), 20; got != want {
  21. t.Fatalf("len mismatch: got %d want %d", got, want)
  22. }
  23. if got, want := int(real(out[0])), 4; got != want {
  24. t.Fatalf("first sample mismatch: got %d want %d", got, want)
  25. }
  26. if got, want := int(real(out[len(out)-1])), 23; got != want {
  27. t.Fatalf("last sample mismatch: got %d want %d", got, want)
  28. }
  29. }
  30. func TestRingSampleCapacityVariablePushSizes(t *testing.T) {
  31. r := NewRing(100, 10, 1) // 100 samples capacity
  32. base := time.Unix(1700001000, 0)
  33. offset := 0
  34. for i := 0; i < 10; i++ {
  35. block := make([]complex64, 15)
  36. for j := range block {
  37. block[j] = complex(float32(offset+j), 0)
  38. }
  39. t0 := base.Add(time.Duration(float64(offset) / 100.0 * float64(time.Second)))
  40. r.Push(t0, block)
  41. offset += len(block)
  42. }
  43. out := r.Slice(base, base.Add(3*time.Second))
  44. if got, want := len(out), 100; got != want {
  45. t.Fatalf("len mismatch: got %d want %d", got, want)
  46. }
  47. if got, want := int(real(out[0])), 50; got != want {
  48. t.Fatalf("first sample mismatch: got %d want %d", got, want)
  49. }
  50. if got, want := int(real(out[len(out)-1])), 149; got != want {
  51. t.Fatalf("last sample mismatch: got %d want %d", got, want)
  52. }
  53. }