kgames

KGames — free keyboard games for kids
git clone https://www.keyboard.games/code/kgames.git
Log | Files | Refs | README | LICENSE

animal-spell-lib.test.js (1707B)


      1 'use strict';
      2 const { test } = require('node:test');
      3 const assert   = require('node:assert/strict');
      4 
      5 require('../../games/animal-letter/lib.js');
      6 const lib = require('../../games/animal-spell/lib.js');
      7 
      8 test('getWordLetters splits name into uppercase letters', () => {
      9   const cat = lib.ANIMALS.find(a => a.key === 'cat');
     10   assert.ok(cat, 'cat should be in ANIMALS');
     11   assert.deepEqual(lib.getWordLetters(cat), ['C', 'A', 'T']);
     12 });
     13 
     14 test('getWordLetters works for longer animal names', () => {
     15   const alligator = lib.ANIMALS.find(a => a.key === 'alligator');
     16   assert.ok(alligator);
     17   assert.deepEqual(lib.getWordLetters(alligator), ['A', 'L', 'L', 'I', 'G', 'A', 'T', 'O', 'R']);
     18 });
     19 
     20 test('getWordLetters length matches animal name length', () => {
     21   lib.ANIMALS.forEach(a => {
     22     assert.equal(lib.getWordLetters(a).length, a.name.length,
     23       `${a.name}: letter count mismatch`);
     24   });
     25 });
     26 
     27 test('all getWordLetters results are uppercase single letters', () => {
     28   lib.ANIMALS.forEach(a => {
     29     lib.getWordLetters(a).forEach(ch => {
     30       assert.match(ch, /^[A-Z]$/, `${a.name} produced non-letter: ${ch}`);
     31     });
     32   });
     33 });
     34 
     35 test('ANIMALS list is shared with AnimalLetterLib', () => {
     36   assert.equal(lib.ANIMALS.length, 51);
     37   lib.ANIMALS.forEach(a => {
     38     assert.ok(a.key);
     39     assert.ok(a.letter);
     40     assert.ok(a.name);
     41     assert.ok(a.codepoint);
     42   });
     43 });
     44 
     45 test('shuffleAnimals returns same animals in different order', () => {
     46   let n = 0;
     47   const rng = () => ((n++ * 137) % 97) / 97;
     48   const shuffled = lib.shuffleAnimals(rng);
     49   assert.equal(shuffled.length, lib.ANIMALS.length);
     50   assert.deepEqual(
     51     shuffled.map(a => a.key).sort(),
     52     lib.ANIMALS.map(a => a.key).sort()
     53   );
     54 });