Skip to content

Commit

Permalink
Add usecaseinformation tests and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Jan 8, 2024
1 parent 47a958b commit 79271ff
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
3 changes: 1 addition & 2 deletions spine/model/usecaseinformation_additions.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ func (u *UseCaseInformationDataType) Remove(useCaseName UseCaseNameType) {

for _, item := range u.UseCaseSupport {
if item.UseCaseName != nil && *item.UseCaseName != useCaseName {
continue
usecases = append(usecases, item)
}

usecases = append(usecases, item)
}

u.UseCaseSupport = usecases
Expand Down
47 changes: 47 additions & 0 deletions spine/model/usecaseinformation_additions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package model

import (
"testing"

"github.com/enbility/eebus-go/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)

func TestUseCaseInformationDataTypeSuite(t *testing.T) {
suite.Run(t, new(UseCaseInformationDataTypeSuite))
}

type UseCaseInformationDataTypeSuite struct {
suite.Suite
}

func (s *UseCaseInformationDataTypeSuite) SetupSuite() {}
func (s *UseCaseInformationDataTypeSuite) TearDownTest() {}

func (s *UseCaseInformationDataTypeSuite) BeforeTest(suiteName, testName string) {}

func (s *UseCaseInformationDataTypeSuite) Test_AdditionsAndRemovals() {
ucs := &UseCaseInformationDataType{}
assert.NotNil(s.T(), ucs)
assert.Equal(s.T(), 0, len(ucs.UseCaseSupport))

uc := UseCaseSupportType{}
ucs.Add(uc)
assert.Equal(s.T(), 0, len(ucs.UseCaseSupport))

uc = UseCaseSupportType{
UseCaseName: util.Ptr(UseCaseNameTypeControlOfBattery),
}
ucs.Add(uc)
assert.Equal(s.T(), 1, len(ucs.UseCaseSupport))

ucs.Add(uc)
assert.Equal(s.T(), 1, len(ucs.UseCaseSupport))

ucs.Remove(UseCaseNameTypeCoordinatedEVCharging)
assert.Equal(s.T(), 1, len(ucs.UseCaseSupport))

ucs.Remove(UseCaseNameTypeControlOfBattery)
assert.Equal(s.T(), 0, len(ucs.UseCaseSupport))
}

0 comments on commit 79271ff

Please sign in to comment.