Skip to content

Commit f565229

Browse files
committed
go: calculateAveragePrice 테스트 추가
1 parent 8d834e2 commit f565229

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package converter
2+
3+
import (
4+
"testing"
5+
6+
"github.com/KubrickCode/loa-work/src/go/libs/loadb"
7+
"github.com/shopspring/decimal"
8+
)
9+
10+
func TestCalculateAveragePrice(t *testing.T) {
11+
tests := []struct {
12+
name string
13+
stats []loadb.AuctionItemStat
14+
expected decimal.Decimal
15+
}{
16+
{
17+
name: "정상적인 가격",
18+
stats: []loadb.AuctionItemStat{
19+
{BuyPrice: 100},
20+
{BuyPrice: 200},
21+
{BuyPrice: 300},
22+
},
23+
expected: decimal.NewFromInt(200),
24+
},
25+
{
26+
name: "빈 배열",
27+
stats: []loadb.AuctionItemStat{},
28+
expected: decimal.NewFromInt(0),
29+
},
30+
{
31+
name: "하나의 가격",
32+
stats: []loadb.AuctionItemStat{
33+
{BuyPrice: 150},
34+
},
35+
expected: decimal.NewFromInt(150),
36+
},
37+
}
38+
39+
for _, tt := range tests {
40+
t.Run(tt.name, func(t *testing.T) {
41+
result := calculateAveragePrice(tt.stats)
42+
if !result.Equal(tt.expected) {
43+
t.Errorf("expected %s, got %s", tt.expected.String(), result.String())
44+
}
45+
})
46+
}
47+
}

0 commit comments

Comments
 (0)