Repository navigation
Expand file tree
/
Copy pathtests.mjs
More file actions
6 lines (6 loc) · 2.15 KB
/
Copy pathtests.mjs
File metadata and controls
6 lines (6 loc) · 2.15 KB
1
2
3
4
5
6
import {test} from 'node:test';import assert from 'node:assert/strict';import {score,blankCard,totals,newGame,roll,commit,hasOpenYahoo} from './engine.mjs';
test('all categories and boundary cases',()=>{for(let i=0;i<6;i++)assert.equal(score([1,2,3,4,6],i),[1,2,3,4,0,6][i]);assert.equal(score([3,3,3,4,5],6),18);assert.equal(score([3,3,4,4,5],6),0);assert.equal(score([6,6,6,6,1],7),25);assert.equal(score([6,6,6,2,1],7),0);assert.equal(score([2,2,5,5,5],8),25);assert.equal(score([5,5,5,5,5],8),0);assert.equal(score([1,2,2,3,4],9),30);assert.equal(score([2,3,4,5,6],10),40);assert.equal(score([1,2,3,4,4],10),0);assert.equal(score([4,4,4,4,4],11),50);assert.equal(score([1,2,3,4,5],12),15);});
test('weighted upper bonuses at exact threshold',()=>{const card=blankCard();for(let r=0;r<6;r++)for(let c=0;c<3;c++)card[r][c]=(r+1)*3*(c+1);assert.deepEqual(totals(card).bonus,[35,70,105]);assert.equal(totals(card).total,588);card[0][0]=2;assert.equal(totals(card).bonus[0],0);});
test('roll limits, selected dice, scoring lock and rotation',()=>{const g=newGame(['A','B']);assert.equal(commit(g,0,0),false);roll(g,()=>0);g.selected[0]=true;roll(g,()=>.99);assert.deepEqual(g.dice,[6,1,1,1,1]);g.selected[1]=true;roll(g,()=>.5);assert.equal(roll(g),false);assert.equal(commit(g,12,2),true);assert.equal(g.players[0].card[12][2],39);assert.equal(g.active,1);assert.equal(g.rolls,0);roll(g,()=>0);commit(g,0,0);assert.equal(g.turn,2);roll(g,()=>0);assert.equal(commit(g,12,2),false);});
test('complete 1–4 player games terminate after 39 turns each',()=>{for(let n=1;n<=4;n++){const g=newGame(Array.from({length:n},(_,i)=>String(i)));for(let r=0;r<13;r++)for(let c=0;c<3;c++)for(let p=0;p<n;p++){assert.equal(roll(g,()=>0),true);assert.equal(commit(g,r,c),true);}assert.equal(g.done,true);assert.equal(roll(g),false);assert.equal(commit(g,0,0),false);}});
test('Yahoo! is only celebrated while a Yahoo! box is open',()=>{const g=newGame(['A','B']);assert.equal(hasOpenYahoo(g.players[0]),true);g.players[0].card[11]=[50,0,150];assert.equal(hasOpenYahoo(g.players[0]),false);assert.equal(hasOpenYahoo(g.players[1]),true);g.players[0].card[11][1]=null;assert.equal(hasOpenYahoo(g.players[0]),true);});