feat(domain): 集数解析纯函数——规则、原号校验(滞后放行)、绝对集号与播出日期换算、建议规则
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
111cbddb36
commit
7b9939e0a0
13 files changed
+991
-1
No files matched your search
@@ -0,0 +1,69 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { type SeasonTable, suggestRule } from "../src/index.ts";
|
||||
|
||||
// 建议规则:发布时间对播出日期配对,试 EP±n / EP*2 / EP*2-1
|
||||
|
||||
function weekly(first: string, count: number) {
|
||||
const t0 = Date.parse(`${first}T00:00:00Z`);
|
||||
return Array.from({ length: count }, (_, i) => ({
|
||||
episode: i + 1,
|
||||
airDate: new Date(t0 + i * 7 * 86_400_000).toISOString().slice(0, 10),
|
||||
}));
|
||||
}
|
||||
|
||||
// S1 2025-10 起 12 集,S2 2026-01-08 起 12 集
|
||||
const t: SeasonTable = {
|
||||
seasons: [
|
||||
{ season: 1, total: 12, episodes: weekly("2025-10-02", 12) },
|
||||
{ season: 2, total: 12, episodes: weekly("2026-01-08", 12) },
|
||||
],
|
||||
latestSeason: 2,
|
||||
ended: false,
|
||||
};
|
||||
const ep = (n: number) => ({ start: n, end: n });
|
||||
|
||||
describe("suggestRule", () => {
|
||||
it("连续编号 13、14、16 都对上 S2 播出 → EP-12 目标季 2", () => {
|
||||
const r = suggestRule(
|
||||
[
|
||||
{ episodes: ep(13), publishedAt: "2026-01-08T15:00:00Z" },
|
||||
{ episodes: ep(14), publishedAt: "2026-01-16T01:00:00Z" },
|
||||
{ episodes: ep(16), publishedAt: "2026-01-29T15:00:00Z" },
|
||||
],
|
||||
t,
|
||||
);
|
||||
expect(r).toMatchObject({ expression: "EP-12", targetSeason: 2 });
|
||||
expect(r?.samples.map((s) => s.target)).toEqual([
|
||||
{ season: 2, episode: 1 },
|
||||
{ season: 2, episode: 2 },
|
||||
{ season: 2, episode: 4 },
|
||||
]);
|
||||
});
|
||||
|
||||
it("双集合并发布:1、2 对上 S2E1、S2E3 → EP*2-1", () => {
|
||||
const r = suggestRule(
|
||||
[
|
||||
{ episodes: ep(1), publishedAt: "2026-01-08T15:00:00Z" },
|
||||
{ episodes: ep(2), publishedAt: "2026-01-22T15:00:00Z" },
|
||||
],
|
||||
t,
|
||||
);
|
||||
expect(r).toMatchObject({ expression: "EP*2-1", targetSeason: 2 });
|
||||
});
|
||||
|
||||
it("样本不足(1 个)→ null", () => {
|
||||
expect(suggestRule([{ episodes: ep(13), publishedAt: "2026-01-08T15:00:00Z" }], t)).toBeNull();
|
||||
});
|
||||
|
||||
it("样本冲突(第二个发布时间对不上同一偏移)→ null", () => {
|
||||
expect(
|
||||
suggestRule(
|
||||
[
|
||||
{ episodes: ep(13), publishedAt: "2026-01-08T15:00:00Z" },
|
||||
{ episodes: ep(14), publishedAt: "2026-03-01T15:00:00Z" },
|
||||
],
|
||||
t,
|
||||
),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user