58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package finance
|
|
|
|
import "testing"
|
|
|
|
func TestClassifyOrderSpendingNormal(t *testing.T) {
|
|
got := ClassifyOrderSpending(2, "O2026", 1000, 200, "", 0)
|
|
if got.IsGamePass {
|
|
t.Fatalf("expected non game pass")
|
|
}
|
|
if got.Total != 1200 || got.PaidCoupon != 1200 || got.GamePass != 0 {
|
|
t.Fatalf("unexpected breakdown: %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestClassifyOrderSpendingGamePass(t *testing.T) {
|
|
got := ClassifyOrderSpending(4, "GP2026", 0, 0, "use_game_pass", 2000)
|
|
if !got.IsGamePass {
|
|
t.Fatalf("expected game pass")
|
|
}
|
|
if got.Total != 2000 || got.PaidCoupon != 0 || got.GamePass != 2000 {
|
|
t.Fatalf("unexpected breakdown: %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestComputePrizeCostWithMultiplier(t *testing.T) {
|
|
got := ComputePrizeCostWithMultiplier(1500, 2000)
|
|
if got != 3000 {
|
|
t.Fatalf("expected 3000 got %d", got)
|
|
}
|
|
}
|
|
|
|
func TestProfitNormalOrder(t *testing.T) {
|
|
sp := ClassifyOrderSpending(2, "O1", 1000, 200, "", 0)
|
|
profit, _ := ComputeProfit(sp.Total, 900)
|
|
if profit != 300 {
|
|
t.Fatalf("expected 300 got %d", profit)
|
|
}
|
|
}
|
|
|
|
func TestProfitGamePassOrder(t *testing.T) {
|
|
gpValue := ComputeGamePassValue(2, 1000)
|
|
sp := ClassifyOrderSpending(4, "GP1", 0, 0, "use_game_pass", gpValue)
|
|
profit, _ := ComputeProfit(sp.Total, 1500)
|
|
if profit != 500 {
|
|
t.Fatalf("expected 500 got %d", profit)
|
|
}
|
|
}
|
|
|
|
func TestProfitGamePassOrderWithMultiplier(t *testing.T) {
|
|
gpValue := ComputeGamePassValue(2, 1000)
|
|
sp := ClassifyOrderSpending(4, "GP1", 0, 0, "use_game_pass", gpValue)
|
|
cost := ComputePrizeCostWithMultiplier(1500, 2000)
|
|
profit, _ := ComputeProfit(sp.Total, cost)
|
|
if profit != -1000 {
|
|
t.Fatalf("expected -1000 got %d", profit)
|
|
}
|
|
}
|