diff --git a/pkg/descriptor/signal_test.go b/pkg/descriptor/signal_test.go index 92d4d02..9277973 100644 --- a/pkg/descriptor/signal_test.go +++ b/pkg/descriptor/signal_test.go @@ -1,6 +1,7 @@ package descriptor import ( + "encoding/hex" "math" "testing" @@ -21,10 +22,17 @@ func TestSignal_Decode_UnsignedBigEndian(t *testing.T) { Max: 1, } const value uint64 = 180 + + // Testing can.Data var data can.Data data.SetUnsignedBitsBigEndian(uint8(s.Start), uint8(s.Length), value) actual := s.Decode(data) assert.DeepEqual(t, s.Offset+float64(value)*s.Scale, actual) + + // Testing payload + p, _ := can.PayloadFromHex(hex.EncodeToString(data[:])) + actual = s.DecodePayload(&p) + assert.DeepEqual(t, s.Offset+float64(value)*s.Scale, actual) } func TestSignal_Decode_SignedBigEndian(t *testing.T) { @@ -40,10 +48,17 @@ func TestSignal_Decode_SignedBigEndian(t *testing.T) { Max: 1, } const value int64 = -180 + + // Testing can.Data var data can.Data data.SetSignedBitsBigEndian(uint8(s.Start), uint8(s.Length), value) actual := s.Decode(data) assert.DeepEqual(t, s.Offset+float64(value)*s.Scale, actual) + + // Testing payload + p, _ := can.PayloadFromHex(hex.EncodeToString(data[:])) + actual = s.DecodePayload(&p) + assert.DeepEqual(t, s.Offset+float64(value)*s.Scale, actual) } func TestSignal_Decode_UnsignedLittleEndian(t *testing.T) { @@ -59,10 +74,17 @@ func TestSignal_Decode_UnsignedLittleEndian(t *testing.T) { Max: 1, } const value uint64 = 180 + + // Testing can.Data var data can.Data data.SetUnsignedBitsLittleEndian(uint8(s.Start), uint8(s.Length), value) actual := s.Decode(data) assert.DeepEqual(t, s.Offset+float64(value)*s.Scale, actual) + + // Testing payload + p, _ := can.PayloadFromHex(hex.EncodeToString(data[:])) + actual = s.DecodePayload(&p) + assert.DeepEqual(t, s.Offset+float64(value)*s.Scale, actual) } func TestSignal_Decode_SignedLittleEndian(t *testing.T) { @@ -78,10 +100,17 @@ func TestSignal_Decode_SignedLittleEndian(t *testing.T) { Max: 1, } const value int64 = -180 + + // Testing can.Data var data can.Data data.SetSignedBitsLittleEndian(uint8(s.Start), uint8(s.Length), value) actual := s.Decode(data) assert.DeepEqual(t, s.Offset+float64(value)*s.Scale, actual) + + // Testing payload + p, _ := can.PayloadFromHex(hex.EncodeToString(data[:])) + actual = s.DecodePayload(&p) + assert.DeepEqual(t, s.Offset+float64(value)*s.Scale, actual) } func TestSignal_FromPhysical_SaturatedCast(t *testing.T) {