fft_aligner_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package sub_timeline_fixer
  2. import (
  3. "gonum.org/v1/gonum/floats/scalar"
  4. "testing"
  5. )
  6. func TestFFTAligner_Fit(t *testing.T) {
  7. type args struct {
  8. refFloats []float64
  9. subFloats []float64
  10. }
  11. tests := []struct {
  12. name string
  13. args args
  14. wantIndex int
  15. wantScore float64
  16. }{
  17. {name: "3-4", args: args{
  18. refFloats: []float64{1, 1, 1, 1, 1, -1, 1},
  19. subFloats: []float64{1, 1, -1, 1},
  20. }, wantIndex: 3, wantScore: 4},
  21. {name: "3-5", args: args{
  22. refFloats: []float64{0, 1, 1, 1, 1, -1, -1, 1},
  23. subFloats: []float64{1, 1, -1, -1, 1},
  24. }, wantIndex: 3, wantScore: 5},
  25. }
  26. const tol = 1e-10
  27. for _, tt := range tests {
  28. t.Run(tt.name, func(t *testing.T) {
  29. f := NewFFTAligner(2, 2)
  30. index, score := f.Fit(tt.args.refFloats, tt.args.subFloats)
  31. if index != tt.wantIndex {
  32. t.Errorf("Fit() wantIndex = %v, want %v", index, tt.wantIndex)
  33. }
  34. if scalar.EqualWithinAbsOrRel(score, tt.wantScore, tol, tol) == false {
  35. t.Errorf("Fit() wantScore = %v, want %v", score, tt.wantScore)
  36. }
  37. })
  38. }
  39. }