mirror of
https://github.com/jwetzell/psn-go.git
synced 2026-09-02 12:59:12 +00:00
add tests for encoding data tracker fields
This commit is contained in:
@@ -0,0 +1,40 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/psn-go/internal/decoders"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDataTrackerAccelChunkEncoding(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
description string
|
||||||
|
expected []byte
|
||||||
|
data decoders.DataTrackerXYZChunkData
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
description: "basic acceleration",
|
||||||
|
expected: []byte{
|
||||||
|
4, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
|
||||||
|
},
|
||||||
|
data: decoders.DataTrackerXYZChunkData{
|
||||||
|
X: 1,
|
||||||
|
Y: 2,
|
||||||
|
Z: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
|
||||||
|
actual := EncodeDataTrackerAccelChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||||
|
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||||
|
fmt.Printf("expected: %v\n", testCase.expected)
|
||||||
|
fmt.Printf("actual: %v\n", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/psn-go/internal/decoders"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDataTrackerOriChunkEncoding(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
description string
|
||||||
|
expected []byte
|
||||||
|
data decoders.DataTrackerXYZChunkData
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
description: "basic orientation",
|
||||||
|
expected: []byte{
|
||||||
|
2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
|
||||||
|
},
|
||||||
|
data: decoders.DataTrackerXYZChunkData{
|
||||||
|
X: 1,
|
||||||
|
Y: 2,
|
||||||
|
Z: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
|
||||||
|
actual := EncodeDataTrackerOriChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||||
|
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||||
|
fmt.Printf("expected: %v\n", testCase.expected)
|
||||||
|
fmt.Printf("actual: %v\n", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/psn-go/internal/decoders"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDataTrackerPosChunkEncoding(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
description string
|
||||||
|
expected []byte
|
||||||
|
data decoders.DataTrackerXYZChunkData
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
description: "basic position",
|
||||||
|
expected: []byte{
|
||||||
|
0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
|
||||||
|
},
|
||||||
|
data: decoders.DataTrackerXYZChunkData{
|
||||||
|
X: 1,
|
||||||
|
Y: 2,
|
||||||
|
Z: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
|
||||||
|
actual := EncodeDataTrackerPosChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||||
|
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||||
|
fmt.Printf("expected: %v\n", testCase.expected)
|
||||||
|
fmt.Printf("actual: %v\n", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/psn-go/internal/decoders"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDataTrackerSpeedChunkEncoding(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
description string
|
||||||
|
expected []byte
|
||||||
|
data decoders.DataTrackerXYZChunkData
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
description: "basic speed",
|
||||||
|
expected: []byte{
|
||||||
|
1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
|
||||||
|
},
|
||||||
|
data: decoders.DataTrackerXYZChunkData{
|
||||||
|
X: 1,
|
||||||
|
Y: 2,
|
||||||
|
Z: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
|
||||||
|
actual := EncodeDataTrackerSpeedChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||||
|
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||||
|
fmt.Printf("expected: %v\n", testCase.expected)
|
||||||
|
fmt.Printf("actual: %v\n", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/psn-go/internal/decoders"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDataTrackerStatusChunkEncoding(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
description string
|
||||||
|
expected []byte
|
||||||
|
data decoders.DataTrackerStatusChunkData
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
description: "basic status",
|
||||||
|
expected: []byte{
|
||||||
|
3, 0, 4, 0, 0, 0, 128, 63,
|
||||||
|
},
|
||||||
|
data: decoders.DataTrackerStatusChunkData{
|
||||||
|
Validity: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
|
||||||
|
actual := EncodeDataTrackerStatusChunk(testCase.data.Validity)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||||
|
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||||
|
fmt.Printf("expected: %v\n", testCase.expected)
|
||||||
|
fmt.Printf("actual: %v\n", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/psn-go/internal/decoders"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDataTrackerTimestampChunkEncoding(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
description string
|
||||||
|
expected []byte
|
||||||
|
data decoders.DataTrackerTimestampChunkData
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
description: "basic timestamp",
|
||||||
|
expected: []byte{
|
||||||
|
6, 0, 8, 0, 210, 2, 150, 73, 0, 0, 0, 0,
|
||||||
|
},
|
||||||
|
data: decoders.DataTrackerTimestampChunkData{
|
||||||
|
Timestamp: 1234567890,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
|
||||||
|
actual := EncodeDataTrackerTimestampChunk(testCase.data.Timestamp)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||||
|
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||||
|
fmt.Printf("expected: %v\n", testCase.expected)
|
||||||
|
fmt.Printf("actual: %v\n", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/psn-go/internal/decoders"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDataTrackerTrgtPosChunkEncoding(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
description string
|
||||||
|
expected []byte
|
||||||
|
data decoders.DataTrackerXYZChunkData
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
description: "basic target position",
|
||||||
|
expected: []byte{
|
||||||
|
5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
|
||||||
|
},
|
||||||
|
data: decoders.DataTrackerXYZChunkData{
|
||||||
|
X: 1,
|
||||||
|
Y: 2,
|
||||||
|
Z: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
|
||||||
|
actual := EncodeDataTrackerTrgtPosChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||||
|
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||||
|
fmt.Printf("expected: %v\n", testCase.expected)
|
||||||
|
fmt.Printf("actual: %v\n", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user