github.com/enbility/spine-go@v0.7.0/model/setpoint_additions_test.go (about) 1 package model 2 3 import ( 4 "testing" 5 6 "github.com/enbility/spine-go/util" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestSetpointListDataType_Update(t *testing.T) { 11 sut := SetpointListDataType{ 12 SetpointData: []SetpointDataType{ 13 { 14 SetpointId: util.Ptr(SetpointIdType(0)), 15 Value: NewScaledNumberType(1), 16 }, 17 { 18 SetpointId: util.Ptr(SetpointIdType(1)), 19 Value: NewScaledNumberType(1), 20 }, 21 }, 22 } 23 24 newData := SetpointListDataType{ 25 SetpointData: []SetpointDataType{ 26 { 27 SetpointId: util.Ptr(SetpointIdType(1)), 28 Value: NewScaledNumberType(10), 29 }, 30 }, 31 } 32 33 // Act 34 _, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil) 35 assert.True(t, success) 36 37 data := sut.SetpointData 38 // check the non changing items 39 assert.Equal(t, 2, len(data)) 40 item1 := data[0] 41 assert.Equal(t, 0, int(*item1.SetpointId)) 42 assert.Equal(t, 1.0, item1.Value.GetValue()) 43 // check properties of updated item 44 item2 := data[1] 45 assert.Equal(t, 1, int(*item2.SetpointId)) 46 assert.Equal(t, 10.0, item2.Value.GetValue()) 47 } 48 49 func TestSetpointDescriptionListDataType_Update(t *testing.T) { 50 sut := SetpointDescriptionListDataType{ 51 SetpointDescriptionData: []SetpointDescriptionDataType{ 52 { 53 SetpointId: util.Ptr(SetpointIdType(0)), 54 Description: util.Ptr(DescriptionType("old")), 55 }, 56 { 57 SetpointId: util.Ptr(SetpointIdType(1)), 58 Description: util.Ptr(DescriptionType("old")), 59 }, 60 }, 61 } 62 63 newData := SetpointDescriptionListDataType{ 64 SetpointDescriptionData: []SetpointDescriptionDataType{ 65 { 66 SetpointId: util.Ptr(SetpointIdType(1)), 67 Description: util.Ptr(DescriptionType("new")), 68 }, 69 }, 70 } 71 72 // Act 73 _, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil) 74 assert.True(t, success) 75 76 data := sut.SetpointDescriptionData 77 // check the non changing items 78 assert.Equal(t, 2, len(data)) 79 item1 := data[0] 80 assert.Equal(t, 0, int(*item1.SetpointId)) 81 assert.Equal(t, "old", string(*item1.Description)) 82 // check properties of updated item 83 item2 := data[1] 84 assert.Equal(t, 1, int(*item2.SetpointId)) 85 assert.Equal(t, "new", string(*item2.Description)) 86 }