Checkpoint

This commit is contained in:
maze authored and maze committed 2026-10-29 17:28:51 +01:00
1 parent 7b6db17870
commit 0295eb1ad2
125 files changed
+59376

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
package moode
import (
"testing"
"git.maze.io/go/bragi/player"
"periph.io/x/conn/v3/physic"
)
func TestParseAudioFormat(t *testing.T) {
testCases := []struct {
Test string
Want player.AudioFormat
}{
{"PCM 16/44.1 kHz, 2ch", player.AudioFormat{Encoding: "PCM", Bits: 16, SampleRate: 44100 * physic.Hertz, Channels: 2}},
{"FLAC 24/48.0 kHz, 2ch", player.AudioFormat{Encoding: "FLAC", Bits: 24, SampleRate: 48 * physic.KiloHertz, Channels: 2}},
{"MP3 16/44.1 kHz, 2ch", player.AudioFormat{Encoding: "MP3", Bits: 16, SampleRate: 44100 * physic.Hertz, Channels: 2}},
{"AAC 24/96.0 kHz, 2ch", player.AudioFormat{Encoding: "AAC", Bits: 24, SampleRate: 96 * physic.KiloHertz, Channels: 2}},
{"WAV 16/44.1 kHz, 1ch", player.AudioFormat{Encoding: "WAV", Bits: 16, SampleRate: 44100 * physic.Hertz, Channels: 1}},
}
for _, test := range testCases {
t.Run(test.Test, func(it *testing.T) {
f, err := parseAudioFormat(test.Test)
if err != nil {
it.Fatal(err)
}
if f.Encoding != test.Want.Encoding {
it.Errorf("expected encoding %q, got %q", test.Want.Encoding, f.Encoding)
}
if f.Bits != test.Want.Bits {
it.Errorf("expected bits %d, got %d", test.Want.Bits, f.Bits)
}
if f.SampleRate != test.Want.SampleRate {
it.Errorf("expected sample rate %d, got %d", test.Want.SampleRate, f.SampleRate)
}
if f.Channels != test.Want.Channels {
it.Errorf("expected channels %d, got %d", test.Want.Channels, f.Channels)
}
it.Log(f)
})
}
}