feat: add outlier score formula and save decision
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
8dbb0cf9ce
commit
b52c847068
@@ -0,0 +1,44 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { computeScore, shouldSave } from '../src/lib/score.js';
|
||||
|
||||
test('computeScore divides views by subscribers', () => {
|
||||
assert.equal(computeScore(100000, 20000), 5);
|
||||
assert.equal(computeScore(2500, 1000), 2.5);
|
||||
});
|
||||
|
||||
test('computeScore rounds to two decimals', () => {
|
||||
assert.equal(computeScore(10000, 3000), 3.33);
|
||||
});
|
||||
|
||||
test('computeScore never divides by zero', () => {
|
||||
assert.equal(computeScore(5000, 0), 5000);
|
||||
});
|
||||
|
||||
test('computeScore returns null when subscribers are unknown', () => {
|
||||
assert.equal(computeScore(5000, null), null);
|
||||
assert.equal(computeScore(5000, undefined), null);
|
||||
});
|
||||
|
||||
const settings = { threshold: 5, minViews: 10000 };
|
||||
|
||||
test('shouldSave accepts a video exactly at both limits', () => {
|
||||
assert.equal(shouldSave({ views: 10000, score: 5, vidiqScore: null }, settings), true);
|
||||
});
|
||||
|
||||
test('shouldSave rejects a score below the threshold', () => {
|
||||
assert.equal(shouldSave({ views: 50000, score: 4.99, vidiqScore: null }, settings), false);
|
||||
});
|
||||
|
||||
test('shouldSave rejects views below the minimum even with a huge score', () => {
|
||||
assert.equal(shouldSave({ views: 9999, score: 50, vidiqScore: null }, settings), false);
|
||||
});
|
||||
|
||||
test('shouldSave rejects a null score without a VidIQ score', () => {
|
||||
assert.equal(shouldSave({ views: 500000, score: null, vidiqScore: null }, settings), false);
|
||||
});
|
||||
|
||||
test('shouldSave accepts any video that has a VidIQ score', () => {
|
||||
assert.equal(shouldSave({ views: 100, score: null, vidiqScore: 7.5 }, settings), true);
|
||||
assert.equal(shouldSave({ views: 100, score: 0.01, vidiqScore: 3 }, settings), true);
|
||||
});
|
||||
Reference in New Issue
Block a user