add unit test

This commit is contained in:
MaysWind
2024-09-03 00:16:41 +08:00
parent dbb1843285
commit 1d43eda9b7
9 changed files with 434 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
package models
import (
"sort"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAccountInfoResponseSliceLess(t *testing.T) {
var accountRespSlice AccountInfoResponseSlice
accountRespSlice = append(accountRespSlice, &AccountInfoResponse{
Id: 1,
Category: ACCOUNT_CATEGORY_DEBIT_CARD,
DisplayOrder: int32(1),
})
accountRespSlice = append(accountRespSlice, &AccountInfoResponse{
Id: 2,
Category: ACCOUNT_CATEGORY_CASH,
DisplayOrder: int32(3),
})
accountRespSlice = append(accountRespSlice, &AccountInfoResponse{
Id: 3,
Category: ACCOUNT_CATEGORY_CREDIT_CARD,
DisplayOrder: int32(2),
})
accountRespSlice = append(accountRespSlice, &AccountInfoResponse{
Id: 4,
Category: ACCOUNT_CATEGORY_CASH,
DisplayOrder: int32(2),
})
accountRespSlice = append(accountRespSlice, &AccountInfoResponse{
Id: 5,
Category: ACCOUNT_CATEGORY_CREDIT_CARD,
DisplayOrder: int32(1),
})
accountRespSlice = append(accountRespSlice, &AccountInfoResponse{
Id: 6,
Category: ACCOUNT_CATEGORY_CASH,
DisplayOrder: int32(1),
})
sort.Sort(accountRespSlice)
assert.Equal(t, int64(6), accountRespSlice[0].Id)
assert.Equal(t, int64(4), accountRespSlice[1].Id)
assert.Equal(t, int64(2), accountRespSlice[2].Id)
assert.Equal(t, int64(1), accountRespSlice[3].Id)
assert.Equal(t, int64(5), accountRespSlice[4].Id)
assert.Equal(t, int64(3), accountRespSlice[5].Id)
}