/**
* Tests for tricky words resource
*/
import {
getTrickyWords,
getTrickyWordByName,
TRICKY_WORDS,
} from '../src/resources/tricky-words.js';
describe('TRICKY_WORDS data', () => {
it('should have multiple tricky words', () => {
expect(TRICKY_WORDS.length).toBeGreaterThan(10);
});
it('should have valid structure for all entries', () => {
for (const word of TRICKY_WORDS) {
expect(typeof word.word).toBe('string');
expect(typeof word.letter).toBe('string');
expect(word.letter).toHaveLength(1);
expect(typeof word.count).toBe('number');
expect(Array.isArray(word.positions)).toBe(true);
expect(word.positions).toHaveLength(word.count);
expect(typeof word.common_mistake).toBe('number');
expect(typeof word.explanation).toBe('string');
}
});
it('should have accurate counts for strawberry', () => {
const strawberry = TRICKY_WORDS.find(w => w.word === 'strawberry' && w.letter === 'r');
expect(strawberry).toBeDefined();
expect(strawberry?.count).toBe(3);
expect(strawberry?.positions).toEqual([2, 7, 8]);
});
it('should have accurate counts for mississippi "s"', () => {
const mississippi = TRICKY_WORDS.find(w => w.word === 'mississippi' && w.letter === 's');
expect(mississippi).toBeDefined();
expect(mississippi?.count).toBe(4);
expect(mississippi?.positions).toEqual([2, 3, 5, 6]);
});
it('should have accurate counts for mississippi "i"', () => {
const mississippi = TRICKY_WORDS.find(w => w.word === 'mississippi' && w.letter === 'i');
expect(mississippi).toBeDefined();
expect(mississippi?.count).toBe(4);
expect(mississippi?.positions).toEqual([1, 4, 7, 10]);
});
it('should have common_mistake different from actual count', () => {
for (const word of TRICKY_WORDS) {
expect(word.common_mistake).not.toBe(word.count);
}
});
});
describe('getTrickyWords', () => {
it('should return all tricky words', () => {
const result = getTrickyWords();
expect(result.total_words).toBe(TRICKY_WORDS.length);
expect(result.words).toEqual(TRICKY_WORDS);
});
it('should categorize by double letters', () => {
const result = getTrickyWords();
expect(result.categories.double_letters.length).toBeGreaterThan(0);
for (const word of result.categories.double_letters) {
expect(word.count).toBe(2);
}
});
it('should categorize by triple or more', () => {
const result = getTrickyWords();
expect(result.categories.triple_or_more.length).toBeGreaterThan(0);
for (const word of result.categories.triple_or_more) {
expect(word.count).toBeGreaterThanOrEqual(3);
}
});
});
describe('getTrickyWordByName', () => {
it('should find strawberry', () => {
const result = getTrickyWordByName('strawberry');
expect(result.length).toBeGreaterThan(0);
expect(result[0].word).toBe('strawberry');
});
it('should be case insensitive', () => {
const result = getTrickyWordByName('STRAWBERRY');
expect(result.length).toBeGreaterThan(0);
expect(result[0].word).toBe('strawberry');
});
it('should return multiple entries for words with multiple tricky letters', () => {
const result = getTrickyWordByName('mississippi');
expect(result.length).toBeGreaterThan(1); // s, i, and p
});
it('should return empty array for non-tricky words', () => {
const result = getTrickyWordByName('cat');
expect(result).toEqual([]);
});
it('should return empty array for unknown words', () => {
const result = getTrickyWordByName('xyzzy');
expect(result).toEqual([]);
});
});
describe('Position verification', () => {
// Verify that all positions in TRICKY_WORDS are accurate
it('should have accurate positions for all entries', () => {
for (const entry of TRICKY_WORDS) {
const word = entry.word.toLowerCase();
const letter = entry.letter.toLowerCase();
// Find all actual positions
const actualPositions: number[] = [];
for (let i = 0; i < word.length; i++) {
if (word[i] === letter) {
actualPositions.push(i);
}
}
expect(entry.positions).toEqual(actualPositions);
expect(entry.count).toBe(actualPositions.length);
}
});
});