Skip to content

Commit

Permalink
Added unit tests for Decode() to signal_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Naveen Venkatesan committed Mar 23, 2021
1 parent b87d69e commit 592beb4
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions pkg/descriptor/signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,82 @@ import (
"gotest.tools/v3/assert"
)

func TestSignal_Decode_UnsignedBigEndian(t *testing.T) {
s := &Signal{
Name: "TestSignal",
IsSigned: false,
IsBigEndian: true,
Offset: -1,
Scale: 3.0517578125e-05,
Length: 10,
Start: 32,
Min: 0,
Max: 1,
}
const value uint64 = 180
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)
}

func TestSignal_Decode_SignedBigEndian(t *testing.T) {
s := &Signal{
Name: "TestSignal",
IsSigned: true,
IsBigEndian: true,
Offset: -1,
Scale: 3.0517578125e-05,
Length: 10,
Start: 32,
Min: -1,
Max: 1,
}
const value int64 = -180
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)
}

func TestSignal_Decode_UnsignedLittleEndian(t *testing.T) {
s := &Signal{
Name: "TestSignal",
IsSigned: false,
IsBigEndian: false,
Offset: -1,
Scale: 3.0517578125e-05,
Length: 10,
Start: 32,
Min: 0,
Max: 1,
}
const value uint64 = 180
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)
}

func TestSignal_Decode_SignedLittleEndian(t *testing.T) {
s := &Signal{
Name: "TestSignal",
IsSigned: true,
IsBigEndian: false,
Offset: -1,
Scale: 3.0517578125e-05,
Length: 10,
Start: 32,
Min: -1,
Max: 1,
}
const value int64 = -180
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)
}

func TestSignal_FromPhysical_SaturatedCast(t *testing.T) {
s := &Signal{
Name: "TestSignal",
Expand Down

0 comments on commit 592beb4

Please sign in to comment.