test: rewrite smart-match-pool test for computeLimitFromClipCount (#1899)
This commit is contained in:
@@ -1,40 +1,33 @@
|
||||
/**
|
||||
* 智能匹配候选池数量规则单测(#1744/#1750)
|
||||
* 智能匹配候选池数量规则单测(#1744/#1750/#1899)
|
||||
*
|
||||
* #1750 基线:模板只有片段数/结构、没有时长概念——候选池纯按「片段数 × 3」
|
||||
* (每个片段至少 3 个候选供变体间洗牌避让),不再参考任何 duration 字段;
|
||||
* 结果钳制到 [1, 200](后端 limit 上限 200);无片段信息时兜底 30。
|
||||
* #1899 简化后:候选池 = 片段数(clipCount) × 3
|
||||
* 结果钳制到 [1, 200](后端 limit 上限 200);clipCount <= 0 时兜底 30。
|
||||
*/
|
||||
import { describe, it, expect } from "vitest"
|
||||
import { computeLimitFromSegments } from "@/pages/generate/hooks/step2-materials/useSmartMatch"
|
||||
import type { TemplateSegment } from "@/api/templates/types"
|
||||
import { computeLimitFromClipCount } from "@/pages/generate/hooks/step2-materials/useSmartMatch"
|
||||
|
||||
function segs(n: number): TemplateSegment[] {
|
||||
// 新规则只看片段数量,duration 字段已废弃,这里不再构造
|
||||
return Array.from({ length: n }, () => ({}) as TemplateSegment)
|
||||
}
|
||||
|
||||
describe("computeLimitFromSegments (#1750 候选池 = 片段数×3)", () => {
|
||||
it("无 segments 时返回兜底 30", () => {
|
||||
expect(computeLimitFromSegments(undefined)).toBe(30)
|
||||
expect(computeLimitFromSegments([])).toBe(30)
|
||||
describe("computeLimitFromClipCount (#1899 候选池 = 片段数×3)", () => {
|
||||
it("clipCount <= 0 时返回兜底 30", () => {
|
||||
expect(computeLimitFromClipCount(0)).toBe(30)
|
||||
expect(computeLimitFromClipCount(-1)).toBe(30)
|
||||
})
|
||||
|
||||
it("候选池 = 片段数 × 3(与任何时长字段无关)", () => {
|
||||
expect(computeLimitFromSegments(segs(1))).toBe(3)
|
||||
expect(computeLimitFromSegments(segs(3))).toBe(9)
|
||||
expect(computeLimitFromSegments(segs(5))).toBe(15)
|
||||
expect(computeLimitFromSegments(segs(10))).toBe(30)
|
||||
it("候选池 = 片段数 × 3", () => {
|
||||
expect(computeLimitFromClipCount(1)).toBe(3)
|
||||
expect(computeLimitFromClipCount(3)).toBe(9)
|
||||
expect(computeLimitFromClipCount(5)).toBe(15)
|
||||
expect(computeLimitFromClipCount(10)).toBe(30)
|
||||
})
|
||||
|
||||
it("超过上限钳制为 200(后端 limit 上限)", () => {
|
||||
expect(computeLimitFromSegments(segs(67))).toBe(200) // 67×3=201 → 200
|
||||
expect(computeLimitFromSegments(segs(100))).toBe(200) // 100×3=300 → 200
|
||||
expect(computeLimitFromClipCount(67)).toBe(200) // 67×3=201 → 200
|
||||
expect(computeLimitFromClipCount(100)).toBe(200) // 100×3=300 → 200
|
||||
})
|
||||
|
||||
it("任何正常片段数下 limit 均 ≥ 1", () => {
|
||||
for (let n = 0; n <= 10; n++) {
|
||||
expect(computeLimitFromSegments(segs(n))).toBeGreaterThanOrEqual(1)
|
||||
it("任何正数片段数下 limit 均 ≥ 1", () => {
|
||||
for (let n = 1; n <= 10; n++) {
|
||||
expect(computeLimitFromClipCount(n)).toBeGreaterThanOrEqual(1)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user