Skip to content

Commit

Permalink
make golden tests more robust
Browse files Browse the repository at this point in the history
There was a floating point near-miss on my system.

--- FAIL: TestSimple (0.00s)
    gosamplerate_test.go:102: input [0.1 -0.5 0.3 0.4 0.1]
    gosamplerate_test.go:103: output [0.1 0.1 -0.1 -0.5 0.033333343 0.33333334 0.4 0.2]
    gosamplerate_test.go:104: unexpected output
FAIL
  • Loading branch information
josharian committed Jan 26, 2024
1 parent e90cbce commit 42e999f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion gosamplerate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ func TestSimple(t *testing.T) {
t.Fatal(err)
}

if !reflect.DeepEqual(output, expectedOutput) {
if !closeEnough(output, expectedOutput) {
t.Log("input", input)
t.Log("output", output)
t.Log("expectedOutput", expectedOutput)
t.Fatal("unexpected output")
}
}
Expand Down Expand Up @@ -295,3 +296,15 @@ func TestErrors(t *testing.T) {
t.Fatal(err)
}
}

func closeEnough(a, b []float32) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v-b[i] > 0.00001 {
return false
}
}
return true
}

0 comments on commit 42e999f

Please sign in to comment.