mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-08-12 10:33:38 +00:00
cleanup test layout
This commit is contained in:
+18
-25
@@ -1,7 +1,6 @@
|
||||
package osc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
@@ -31,7 +30,6 @@ func TestOSCBundleEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestOSCBundleDecoding(t *testing.T) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
expected *OSCBundle
|
||||
bytes []byte
|
||||
name string
|
||||
expected *OSCBundle
|
||||
bytes []byte
|
||||
}{
|
||||
{
|
||||
"simple contents single message",
|
||||
&OSCBundle{
|
||||
name: "simple contents single message",
|
||||
expected: &OSCBundle{
|
||||
TimeTag: OSCTimeTag{
|
||||
seconds: 32,
|
||||
fractionalSeconds: 0,
|
||||
},
|
||||
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,
|
||||
115, 99, 105, 108, 108, 97, 116, 111, 114, 47, 52,
|
||||
47, 102, 114, 101, 113, 117, 101, 110, 99, 121, 0,
|
||||
@@ -73,23 +69,20 @@ func TestOSCBundleDecoding(t *testing.T) {
|
||||
}
|
||||
|
||||
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 {
|
||||
fmt.Println(error)
|
||||
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 len(remainingBytes) > 0 {
|
||||
t.Fatalf("should not have any remaining bytes")
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Fatalf("failed to decode properly got '%v', expected '%v'", actual, testCase.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user