github.com/enbility/spine-go@v0.7.0/model/loadcontrol_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 TestLoadControlEventListDataType_Update(t *testing.T) {
    11  	sut := LoadControlEventListDataType{
    12  		LoadControlEventData: []LoadControlEventDataType{
    13  			{
    14  				EventId:            util.Ptr(LoadControlEventIdType(0)),
    15  				EventActionConsume: util.Ptr(LoadControlEventActionTypeNormal),
    16  			},
    17  			{
    18  				EventId:            util.Ptr(LoadControlEventIdType(1)),
    19  				EventActionConsume: util.Ptr(LoadControlEventActionTypeNormal),
    20  			},
    21  		},
    22  	}
    23  
    24  	newData := LoadControlEventListDataType{
    25  		LoadControlEventData: []LoadControlEventDataType{
    26  			{
    27  				EventId:            util.Ptr(LoadControlEventIdType(1)),
    28  				EventActionConsume: util.Ptr(LoadControlEventActionTypeIncrease),
    29  			},
    30  		},
    31  	}
    32  
    33  	// Act
    34  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
    35  	assert.True(t, success)
    36  
    37  	data := sut.LoadControlEventData
    38  	// check the non changing items
    39  	assert.Equal(t, 2, len(data))
    40  	item1 := data[0]
    41  	assert.Equal(t, 0, int(*item1.EventId))
    42  	assert.Equal(t, LoadControlEventActionTypeNormal, *item1.EventActionConsume)
    43  	// check properties of updated item
    44  	item2 := data[1]
    45  	assert.Equal(t, 1, int(*item2.EventId))
    46  	assert.Equal(t, LoadControlEventActionTypeIncrease, *item2.EventActionConsume)
    47  }
    48  
    49  func TestLoadControlStateListDataType_Update(t *testing.T) {
    50  	sut := LoadControlStateListDataType{
    51  		LoadControlStateData: []LoadControlStateDataType{
    52  			{
    53  				EventId:           util.Ptr(LoadControlEventIdType(0)),
    54  				EventStateConsume: util.Ptr(LoadControlEventStateTypeEventAccepted),
    55  			},
    56  			{
    57  				EventId:           util.Ptr(LoadControlEventIdType(1)),
    58  				EventStateConsume: util.Ptr(LoadControlEventStateTypeEventAccepted),
    59  			},
    60  		},
    61  	}
    62  
    63  	newData := LoadControlStateListDataType{
    64  		LoadControlStateData: []LoadControlStateDataType{
    65  			{
    66  				EventId:           util.Ptr(LoadControlEventIdType(1)),
    67  				EventStateConsume: util.Ptr(LoadControlEventStateTypeEventStopped),
    68  			},
    69  		},
    70  	}
    71  
    72  	// Act
    73  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
    74  	assert.True(t, success)
    75  
    76  	data := sut.LoadControlStateData
    77  	// check the non changing items
    78  	assert.Equal(t, 2, len(data))
    79  	item1 := data[0]
    80  	assert.Equal(t, 0, int(*item1.EventId))
    81  	assert.Equal(t, LoadControlEventStateTypeEventAccepted, *item1.EventStateConsume)
    82  	// check properties of updated item
    83  	item2 := data[1]
    84  	assert.Equal(t, 1, int(*item2.EventId))
    85  	assert.Equal(t, LoadControlEventStateTypeEventStopped, *item2.EventStateConsume)
    86  }
    87  
    88  func TestLoadControlLimitListDataType_Update(t *testing.T) {
    89  	sut := LoadControlLimitListDataType{
    90  		LoadControlLimitData: []LoadControlLimitDataType{
    91  			{
    92  				LimitId:           util.Ptr(LoadControlLimitIdType(0)),
    93  				IsLimitChangeable: util.Ptr(false),
    94  			},
    95  			{
    96  				LimitId:           util.Ptr(LoadControlLimitIdType(1)),
    97  				IsLimitChangeable: util.Ptr(true),
    98  			},
    99  		},
   100  	}
   101  
   102  	newData := LoadControlLimitListDataType{
   103  		LoadControlLimitData: []LoadControlLimitDataType{
   104  			{
   105  				LimitId:           util.Ptr(LoadControlLimitIdType(1)),
   106  				IsLimitChangeable: util.Ptr(true),
   107  				Value:             NewScaledNumberType(10),
   108  			},
   109  		},
   110  	}
   111  
   112  	// Act
   113  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   114  	assert.True(t, success)
   115  
   116  	data := sut.LoadControlLimitData
   117  	// check the non changing items
   118  	assert.Equal(t, 2, len(data))
   119  	item1 := data[0]
   120  	assert.Equal(t, 0, int(*item1.LimitId))
   121  	assert.False(t, *item1.IsLimitChangeable)
   122  	// check properties of updated item
   123  	item2 := data[1]
   124  	assert.Equal(t, 1, int(*item2.LimitId))
   125  	assert.True(t, *item2.IsLimitChangeable)
   126  	assert.Equal(t, 10.0, item2.Value.GetValue())
   127  }
   128  
   129  func TestLoadControlLimitConstraintsListDataType_Update(t *testing.T) {
   130  	sut := LoadControlLimitConstraintsListDataType{
   131  		LoadControlLimitConstraintsData: []LoadControlLimitConstraintsDataType{
   132  			{
   133  				LimitId:       util.Ptr(LoadControlLimitIdType(0)),
   134  				ValueStepSize: NewScaledNumberType(1),
   135  			},
   136  			{
   137  				LimitId:       util.Ptr(LoadControlLimitIdType(1)),
   138  				ValueStepSize: NewScaledNumberType(1),
   139  			},
   140  		},
   141  	}
   142  
   143  	newData := LoadControlLimitConstraintsListDataType{
   144  		LoadControlLimitConstraintsData: []LoadControlLimitConstraintsDataType{
   145  			{
   146  				LimitId:       util.Ptr(LoadControlLimitIdType(1)),
   147  				ValueStepSize: NewScaledNumberType(10),
   148  			},
   149  		},
   150  	}
   151  
   152  	// Act
   153  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   154  	assert.True(t, success)
   155  
   156  	data := sut.LoadControlLimitConstraintsData
   157  	// check the non changing items
   158  	assert.Equal(t, 2, len(data))
   159  	item1 := data[0]
   160  	assert.Equal(t, 0, int(*item1.LimitId))
   161  	assert.Equal(t, 1.0, float64(item1.ValueStepSize.GetValue()))
   162  	// check properties of updated item
   163  	item2 := data[1]
   164  	assert.Equal(t, 1, int(*item2.LimitId))
   165  	assert.Equal(t, 10.0, float64(item2.ValueStepSize.GetValue()))
   166  }
   167  
   168  func TestLoadControlLimitDescriptionListDataType_Update(t *testing.T) {
   169  	sut := LoadControlLimitDescriptionListDataType{
   170  		LoadControlLimitDescriptionData: []LoadControlLimitDescriptionDataType{
   171  			{
   172  				LimitId:       util.Ptr(LoadControlLimitIdType(0)),
   173  				LimitCategory: util.Ptr(LoadControlCategoryTypeObligation),
   174  			},
   175  			{
   176  				LimitId:       util.Ptr(LoadControlLimitIdType(1)),
   177  				LimitCategory: util.Ptr(LoadControlCategoryTypeObligation),
   178  			},
   179  		},
   180  	}
   181  
   182  	newData := LoadControlLimitDescriptionListDataType{
   183  		LoadControlLimitDescriptionData: []LoadControlLimitDescriptionDataType{
   184  			{
   185  				LimitId:       util.Ptr(LoadControlLimitIdType(1)),
   186  				LimitCategory: util.Ptr(LoadControlCategoryTypeOptimization),
   187  			},
   188  		},
   189  	}
   190  
   191  	// Act
   192  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   193  	assert.True(t, success)
   194  
   195  	data := sut.LoadControlLimitDescriptionData
   196  	// check the non changing items
   197  	assert.Equal(t, 2, len(data))
   198  	item1 := data[0]
   199  	assert.Equal(t, 0, int(*item1.LimitId))
   200  	assert.Equal(t, LoadControlCategoryTypeObligation, *item1.LimitCategory)
   201  	// check properties of updated item
   202  	item2 := data[1]
   203  	assert.Equal(t, 1, int(*item2.LimitId))
   204  	assert.Equal(t, LoadControlCategoryTypeOptimization, *item2.LimitCategory)
   205  }