import { describe, expect, it } from 'vitest' import { wordBand } from './wordband' describe('wordBand', () => { it('says nothing when the dictionary knows nothing', () => { // The embedded datasets carry no scores at all, and this is the common // case for a zh-pair writer. An unknown word must produce no chip rather // than a default one — "standard" would be an invention. expect(wordBand(0, -1)).toBeNull() }) it('bands the words a writer actually looks up', () => { // Real scores from the deployed dict.db. These are the sanity checks that // would catch a threshold drifting away from the data. expect(wordBand(1000, 0.304)).toBe('simple') // cat expect(wordBand(1000, 0.326)).toBe('simple') // house, write expect(wordBand(1000, 0.37)).toBe('simple') // beautiful expect(wordBand(600, 0.462)).toBe('standard') // ephemeral expect(wordBand(400, 0.53)).toBe('standard') // serendipity expect(wordBand(50, 0.8)).toBe('advanced') // antidisestablishmentarianism }) it('prefers difficulty over frequency when both are known', () => { // Difficulty is the finer signal — 206 distinct values against frequency's // handful of buckets — so a hard word with a high frequency reads as hard. expect(wordBand(1000, 0.9)).toBe('advanced') expect(wordBand(2, 0.2)).toBe('simple') }) it('falls back to frequency for a word with no difficulty score', () => { expect(wordBand(1000, -1)).toBe('simple') expect(wordBand(500, -1)).toBe('standard') expect(wordBand(10, -1)).toBe('advanced') }) it('treats a difficulty of exactly zero as a score, not as missing', () => { // 0.0 is the easiest word there is. The API sends -1 for unknown precisely // so this case survives; a falsy check here would throw it away. expect(wordBand(0, 0)).toBe('simple') }) })