This repository has been archived on 2019-12-11. You can view files and clone it, but cannot push or open issues/pull-requests.
jlaudio/lib/util/notefreq_test.go

77 lines
1.2 KiB
Go

package util
import (
"fmt"
"testing"
)
func TestNoteFreq(t *testing.T) {
type TestCase struct {
In float64
Out float64
}
testCases := []TestCase{
{108, 4186.01},
{81, 880},
{69, 440},
{58, 233.08},
{57, 220},
{56, 207.65},
{55, 196},
{36, 65.41},
}
for _, tc := range testCases {
out := NoteFreq(tc.In)
if fmt.Sprintf("%.2f", out) != fmt.Sprintf("%.2f", tc.Out) {
t.Fatalf("%v != %v", out, tc.Out)
}
}
}
func TestFreqNote(t *testing.T) {
type TestCase struct {
Out float64
In float64
}
testCases := []TestCase{
{108, 4186.01},
{81, 880},
{69, 440},
{58, 233.08},
{57, 220},
{56, 207.65},
{55, 196},
{36, 65.41},
}
for _, tc := range testCases {
out := FreqNote(tc.In)
if fmt.Sprintf("%.2f", out) != fmt.Sprintf("%.2f", tc.Out) {
t.Fatalf("%v != %v", out, tc.Out)
}
}
}
func TestCentDeltaFreq(t *testing.T) {
type TestCase struct {
In, Out float64
}
testCases := []TestCase{
{27.5, 0.016},
{55, 0.032},
{130.8128, 0.076},
{440, 0.254},
}
for _, tc := range testCases {
out := CentDeltaFreq(tc.In)
if fmt.Sprintf("%.3f", out) != fmt.Sprintf("%.3f", tc.Out) {
t.Fatalf("%v: %v != %v", tc.In, out, tc.Out)
}
}
}