diff --git a/pdu/pdu_test.go b/pdu/pdu_test.go new file mode 100644 index 0000000..fd6d33e --- /dev/null +++ b/pdu/pdu_test.go @@ -0,0 +1,67 @@ +package pdu + +import "testing" + +func TestEncodeReturnsByteSliceOfLength16(t *testing.T) { + p := &PDU_HEADER{ + command_length: 1, + command_id: 1, + command_status: 1, + sequence_number: 1, + } + result := p.Encode() + if len(result) != 16 { + t.Errorf("Expected byte slice of length 16, got %d", len(result)) + } +} + +func TestEncodeHandlesZeroValues(t *testing.T) { + p := &PDU_HEADER{ + command_length: 0, + command_id: 0, + command_status: 0, + sequence_number: 0, + } + result := p.Encode() + expected := make([]byte, 16) + for i, v := range result { + if v != expected[i] { + t.Errorf("Expected byte slice with zero values, got %v", result) + break + } + } +} + +func TestEncodeEncodesProperly(t *testing.T) { + p := &PDU_HEADER{ + command_length: 1, + command_id: 2, + command_status: 3, + sequence_number: 4, + } + result := p.Encode() + expected := []byte{0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4} + for i, v := range result { + if v != expected[i] { + t.Errorf("Expected byte slice with values %v, got %v", expected, result) + break + } + } +} + +func TestEncodeEncodesProperlyComplex(t *testing.T) { + p := &PDU_HEADER{ + command_length: 13426724, + command_id: 254352, + command_status: 35634264, + sequence_number: 476543523, + } + result := p.Encode() + expected := []byte{0, 204, 224, 36, 0, 3, 225, 144, 2, 31, 188, 88, 28, 103, 122, 35} + for i, v := range result { + if v != expected[i] { + t.Errorf("Expected byte slice with values %v, got %v", expected, result) + break + } + } +} \ No newline at end of file