From 75ba02322632d58a55d6999b17696c424b3521e4 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Thu, 16 Oct 2025 21:41:28 -0500 Subject: [PATCH] add tests for decoding status, timestamp and xyz chunks --- .../data_tracker_status_chunk_test.go | 47 ++++++++ .../data_tracker_timestamp_chunk_test.go | 47 ++++++++ .../decoders/data_tracker_xyz_chunk_test.go | 109 ++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 internal/decoders/data_tracker_status_chunk_test.go create mode 100644 internal/decoders/data_tracker_timestamp_chunk_test.go create mode 100644 internal/decoders/data_tracker_xyz_chunk_test.go diff --git a/internal/decoders/data_tracker_status_chunk_test.go b/internal/decoders/data_tracker_status_chunk_test.go new file mode 100644 index 0000000..f6e082b --- /dev/null +++ b/internal/decoders/data_tracker_status_chunk_test.go @@ -0,0 +1,47 @@ +package decoders + +import ( + "fmt" + "reflect" + "testing" +) + +func TestGoodDataTrackerStatusChunk(t *testing.T) { + + testCases := []struct { + description string + bytes []byte + expected DataTrackerStatusChunk + }{ + { + description: "DataTrackerStatusChunk", + bytes: []byte{3, 0, 4, 0, 0, 0, 128, 63}, + expected: DataTrackerStatusChunk{ + Chunk: Chunk{ + ChunkData: []byte{0, 0, 128, 63}, + Header: ChunkHeader{DataLen: 4, Id: 3, HasSubchunks: false}, + }, + Data: DataTrackerStatusChunkData{ + Validity: 1.0, + }, + }, + }, + } + + for _, testCase := range testCases { + + actual, err := DecodeDataTrackerStatusChunk(testCase.bytes) + + if err != nil { + t.Errorf("Test '%s' failed to decode chunk properly", testCase.description) + fmt.Println(err) + } + + if !reflect.DeepEqual(actual, testCase.expected) { + t.Errorf("Test '%s' failed to decode chunk properly", testCase.description) + fmt.Printf("expected: %v\n", testCase.expected) + fmt.Printf("actual: %v\n", actual) + } + } + +} diff --git a/internal/decoders/data_tracker_timestamp_chunk_test.go b/internal/decoders/data_tracker_timestamp_chunk_test.go new file mode 100644 index 0000000..bf44787 --- /dev/null +++ b/internal/decoders/data_tracker_timestamp_chunk_test.go @@ -0,0 +1,47 @@ +package decoders + +import ( + "fmt" + "reflect" + "testing" +) + +func TestGoodDataTrackerTimestampChunk(t *testing.T) { + + testCases := []struct { + description string + bytes []byte + expected DataTrackerTimestampChunk + }{ + { + description: "DataTrackerTimestampChunk", + bytes: []byte{6, 0, 8, 0, 210, 2, 150, 73, 0, 0, 0, 0}, + expected: DataTrackerTimestampChunk{ + Chunk: Chunk{ + ChunkData: []byte{210, 2, 150, 73, 0, 0, 0, 0}, + Header: ChunkHeader{DataLen: 8, Id: 6, HasSubchunks: false}, + }, + Data: DataTrackerTimestampChunkData{ + Timestamp: 1234567890, + }, + }, + }, + } + + for _, testCase := range testCases { + + actual, err := DecodeDataTrackerTimestampChunk(testCase.bytes) + + if err != nil { + t.Errorf("Test '%s' failed to decode chunk properly", testCase.description) + fmt.Println(err) + } + + if !reflect.DeepEqual(actual, testCase.expected) { + t.Errorf("Test '%s' failed to decode chunk properly", testCase.description) + fmt.Printf("expected: %v\n", testCase.expected) + fmt.Printf("actual: %v\n", actual) + } + } + +} diff --git a/internal/decoders/data_tracker_xyz_chunk_test.go b/internal/decoders/data_tracker_xyz_chunk_test.go new file mode 100644 index 0000000..68cd221 --- /dev/null +++ b/internal/decoders/data_tracker_xyz_chunk_test.go @@ -0,0 +1,109 @@ +package decoders + +import ( + "fmt" + "reflect" + "testing" +) + +func TestGoodDataTrackerXYZChunk(t *testing.T) { + + testCases := []struct { + description string + bytes []byte + expected DataTrackerXYZChunk + }{ + { + description: "DataTrackerPosChunk", + bytes: []byte{0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64}, + expected: DataTrackerXYZChunk{ + Chunk: Chunk{ + ChunkData: []byte{0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64}, + Header: ChunkHeader{DataLen: 12, Id: 0, HasSubchunks: false}, + }, + Data: DataTrackerXYZChunkData{ + X: 1.0, + Y: 2.0, + Z: 3.0, + }, + }, + }, + { + description: "DataTrackerSpeedChunk", + bytes: []byte{1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64}, + expected: DataTrackerXYZChunk{ + Chunk: Chunk{ + ChunkData: []byte{0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64}, + Header: ChunkHeader{DataLen: 12, Id: 1, HasSubchunks: false}, + }, + Data: DataTrackerXYZChunkData{ + X: 1.0, + Y: 2.0, + Z: 3.0, + }, + }, + }, + { + description: "DataTrackerOriChunk", + bytes: []byte{2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64}, + expected: DataTrackerXYZChunk{ + Chunk: Chunk{ + ChunkData: []byte{0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64}, + Header: ChunkHeader{DataLen: 12, Id: 2, HasSubchunks: false}, + }, + Data: DataTrackerXYZChunkData{ + X: 1.0, + Y: 2.0, + Z: 3.0, + }, + }, + }, + { + description: "DataTrackerAccelChunk", + bytes: []byte{4, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64}, + expected: DataTrackerXYZChunk{ + Chunk: Chunk{ + ChunkData: []byte{0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64}, + Header: ChunkHeader{DataLen: 12, Id: 4, HasSubchunks: false}, + }, + Data: DataTrackerXYZChunkData{ + X: 1.0, + Y: 2.0, + Z: 3.0, + }, + }, + }, + { + description: "DataTrackerTrgtPosChunk", + bytes: []byte{5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64}, + expected: DataTrackerXYZChunk{ + Chunk: Chunk{ + ChunkData: []byte{0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64}, + Header: ChunkHeader{DataLen: 12, Id: 5, HasSubchunks: false}, + }, + Data: DataTrackerXYZChunkData{ + X: 1.0, + Y: 2.0, + Z: 3.0, + }, + }, + }, + } + + for _, testCase := range testCases { + + actual, err := DecodeDataTrackerXYZChunk(testCase.bytes) + + if err != nil { + t.Errorf("Test '%s' failed to decode chunk properly", testCase.description) + fmt.Println(err) + } + + if !reflect.DeepEqual(actual, testCase.expected) { + t.Errorf("Test '%s' failed to decode chunk properly", testCase.description) + fmt.Printf("expected: %v\n", testCase.expected) + fmt.Printf("actual: %v\n", actual) + } + } + +}