cleanup test layout

This commit is contained in:
Joel Wetzell
2026-04-13 18:53:21 -05:00
parent 2548771fe3
commit 1d2684f446
+18 -25
View File
@@ -1,7 +1,6 @@
package osc package osc
import ( import (
"fmt"
"reflect" "reflect"
"testing" "testing"
) )
@@ -31,7 +30,6 @@ func TestOSCBundleEncoding(t *testing.T) {
} }
for _, testCase := range testCases { for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) { t.Run(testCase.name, func(t *testing.T) {
got, err := testCase.bundle.ToBytes() got, err := testCase.bundle.ToBytes()
@@ -44,27 +42,25 @@ func TestOSCBundleEncoding(t *testing.T) {
t.Fatalf("failed to encode properly got '%v', expected '%v'", got, testCase.expected) t.Fatalf("failed to encode properly got '%v', expected '%v'", got, testCase.expected)
} }
}) })
} }
} }
func TestOSCBundleDecoding(t *testing.T) { func TestOSCBundleDecoding(t *testing.T) {
testCases := []struct { testCases := []struct {
description string name string
expected *OSCBundle expected *OSCBundle
bytes []byte bytes []byte
}{ }{
{ {
"simple contents single message", name: "simple contents single message",
&OSCBundle{ expected: &OSCBundle{
TimeTag: OSCTimeTag{ TimeTag: OSCTimeTag{
seconds: 32, seconds: 32,
fractionalSeconds: 0, fractionalSeconds: 0,
}, },
Contents: []OSCPacket{&OSCMessage{Address: "/oscillator/4/frequency", Args: []OSCArg{{Type: "f", Value: float32(440)}}}}, Contents: []OSCPacket{&OSCMessage{Address: "/oscillator/4/frequency", Args: []OSCArg{{Type: "f", Value: float32(440)}}}},
}, },
[]byte{35, 98, 117, 110, 100, 108, 101, 0, 0, 0, 0, bytes: []byte{35, 98, 117, 110, 100, 108, 101, 0, 0, 0, 0,
32, 0, 0, 0, 0, 0, 0, 0, 32, 47, 111, 32, 0, 0, 0, 0, 0, 0, 0, 32, 47, 111,
115, 99, 105, 108, 108, 97, 116, 111, 114, 47, 52, 115, 99, 105, 108, 108, 97, 116, 111, 114, 47, 52,
47, 102, 114, 101, 113, 117, 101, 110, 99, 121, 0, 47, 102, 114, 101, 113, 117, 101, 110, 99, 121, 0,
@@ -73,23 +69,20 @@ func TestOSCBundleDecoding(t *testing.T) {
} }
for _, testCase := range testCases { for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
actual, remainingBytes, error := BundleFromBytes(testCase.bytes)
actual, remainingBytes, error := BundleFromBytes(testCase.bytes) if error != nil {
t.Fatalf("failed to decode properly: %s", error.Error())
}
if error != nil { if len(remainingBytes) > 0 {
fmt.Println(error) t.Fatalf("should not have any remaining bytes")
t.Errorf("Test '%s' failed to encode properly", testCase.description) }
}
if len(remainingBytes) > 0 {
t.Errorf("Test '%s' should not have any remaining bytes", testCase.description)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to encode bundle properly", testCase.description)
fmt.Printf("expected: %v\n", testCase.expected)
fmt.Printf("actual: %v\n", actual)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Fatalf("failed to decode properly got '%v', expected '%v'", actual, testCase.expected)
}
})
} }
} }