Files
admin 0593ff7e62
nginx serve /uploads direct (audio speed) / patch-nginx (push) Failing after 1m34s
数字我 Digital Me:全量入库(大文件走 Git LFS)
2026-10-10 16:24:43 +08:00

53 lines
2.9 KiB
JavaScript

// 改命打卡 单测 —— 2026-07-21 立(老板:"要按天或周持续有改变才能改命")。
// 锁死:①连续打卡 streak 累加、幂等 ②断了衰减(归 0) ③连续 3 期点亮 ④综合指标按方向数等比守门。
import test from 'node:test';
import assert from 'node:assert/strict';
import { checkin, boardState, gaimingPoints, GAIMING_ITEMS } from '../src/gaiming.js';
const D = (s) => new Date(s + 'T12:00:00Z'); // 固定时间,纯函数可测
test('①日项连续打卡 streak 累加;同一天重复打卡幂等(不重复加)', () => {
let g = {};
g = checkin(g, 'read', D('2026-07-19'));
assert.equal(g.read.streak, 1, '第1天 → 1');
g = checkin(g, 'read', D('2026-07-19')); // 同一天再打
assert.equal(g.read.streak, 1, '★ 同一天重复打卡幂等,仍 1');
g = checkin(g, 'read', D('2026-07-20'));
g = checkin(g, 'read', D('2026-07-21'));
assert.equal(g.read.streak, 3, '连续 3 天 → 3');
});
test('②断了就衰减:隔一天没打,boardState 里 streak 归 0、不点亮', () => {
let g = {};
for (const day of ['2026-07-17', '2026-07-18', '2026-07-19']) g = checkin(g, 'read', D(day));
assert.equal(boardState(g, D('2026-07-19'))[0].streak, 3, '当天看:连 3');
// 到 21 号才看(19 打的,20 没打 → 断了)
const stale = boardState(g, D('2026-07-21')).find((s) => s.id === 'read');
assert.equal(stale.streak, 0, '★ 断了 → 衰减归 0(逼你持续)');
assert.equal(stale.lit, false, '断了不点亮');
});
test('③连续 3 期点亮该项;②周项按周算', () => {
let g = {};
for (const day of ['2026-07-07', '2026-07-14', '2026-07-21']) g = checkin(g, 'social', D(day)); // 三个连续周二
const s = boardState(g, D('2026-07-21')).find((x) => x.id === 'social');
assert.equal(s.streak, 3, '连续 3 周 → 3');
assert.equal(s.lit, true, '★ 连 3 周 → 点亮');
});
test('④方向扩容后门槛等比提高:两项刚点亮不够,持续多项才抬一档', () => {
let g = {};
// read 连 3 天 + earlyrise 连 3 天:综合池只有 2 分,不因可选方向变多而让改命变松。
for (const day of ['2026-07-19', '2026-07-20', '2026-07-21']) { g = checkin(g, 'read', D(day)); g = checkin(g, 'earlyrise', D(day)); }
assert.equal(gaimingPoints(g, D('2026-07-21')), 0, '两项刚点亮仍未达到等比门槛');
// 所有日项连续 7 天,每项进入「稳住」档,足以跨过第一档门槛。
g = {};
const daily = GAIMING_ITEMS.filter((item) => item.cadence === 'day');
for (const day of ['2026-07-15', '2026-07-16', '2026-07-17', '2026-07-18', '2026-07-19', '2026-07-20', '2026-07-21']) {
for (const item of daily) g = checkin(g, item.id, D(day));
}
assert.equal(gaimingPoints(g, D('2026-07-21')), 2, '多方向持续到稳住档 → 后天改命抬一档');
assert.ok(GAIMING_ITEMS.length >= 6, '打卡项日+周至少 6 项(可选项多)');
});