package service import ( "testing" "gitea.starryskymeow.cn/B309/datamarket/internal/repository" ) func TestNormalizePage(t *testing.T) { tests := []struct { name string limit int32 offset int32 wantLimit int32 wantOffset int32 }{ {name: "default values", limit: 0, offset: -1, wantLimit: defaultLimit, wantOffset: 0}, {name: "cap max limit", limit: 999, offset: 3, wantLimit: maxLimit, wantOffset: 3}, {name: "keep valid page", limit: 15, offset: 8, wantLimit: 15, wantOffset: 8}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := normalizePage(tt.limit, tt.offset) if got.Limit != tt.wantLimit || got.Offset != tt.wantOffset { t.Fatalf("normalizePage() = %+v, want limit=%d offset=%d", got, tt.wantLimit, tt.wantOffset) } }) } } func TestBuildAssetDerivedFields(t *testing.T) { input := AssetCreateInput{ AssetName: "机械臂抓取演示数据集A", AssetType: "视频+轨迹", Domain: "机器人", DataDescription: "demo", DataScale: "1200条轨迹", CollectionMethod: "真实采集", LabelingStatus: new("已完整标注"), PrivacyLevel: "中", PermissionMode: "授权访问", SupportsValidation: true, SellerExpectedPriceMin: new(float64(20000)), SellerExpectedPriceMax: new(float64(50000)), } derived, err := buildAssetDerivedFields(input) if err != nil { t.Fatalf("buildAssetDerivedFields() error = %v", err) } if derived.QualityLevel != "高" { t.Fatalf("unexpected quality level: %s", derived.QualityLevel) } if derived.ScarcityLevel != "高" { t.Fatalf("unexpected scarcity level: %s", derived.ScarcityLevel) } if derived.BaseValueScore <= 0 { t.Fatalf("unexpected base value score: %v", derived.BaseValueScore) } if derived.BasePriceMin >= derived.BasePriceMax { t.Fatalf("unexpected base price range: %v - %v", derived.BasePriceMin, derived.BasePriceMax) } } func TestBuildNegotiationRange(t *testing.T) { pricing := repository.PricingResult{ ScenarioPriceMin: numericValue(30000), ScenarioPriceMax: numericValue(42000), } min, max, err := buildNegotiationRange(pricing, 38000) if err != nil { t.Fatalf("buildNegotiationRange() error = %v", err) } if min != 34960 { t.Fatalf("unexpected negotiation min: %v", min) } if max != 41040 { t.Fatalf("unexpected negotiation max: %v", max) } }