49 lines
2.8 KiB
TypeScript
49 lines
2.8 KiB
TypeScript
import assert from 'node:assert/strict';
|
||
import test from 'node:test';
|
||
import {jointRicheseBidCompletionRange,richeseBidsWithPhaseBounds} from '../game/joint-richese-bids';
|
||
import type {RicheseBidOpportunity,RicheseBidPromise} from '../game/richese-bid-promises';
|
||
import type {PhaseBidPromise} from '../game/turn-bid-promises';
|
||
|
||
const opportunity: RicheseBidOpportunity = {turn:2,event:'lot',player:'p',minimum:2,maximum:10};
|
||
const richese = (id:string,minimum:number,answer:boolean): RicheseBidPromise =>
|
||
({id,turn:2,event:'lot',player:'p',asker:'a',minimum,answer});
|
||
const phase = (event:string,minimum:number,answer:boolean): PhaseBidPromise =>
|
||
({event,turn:2,player:'p',asker:'a',minimum,answer});
|
||
|
||
void test('native and phase-wide answers share one funded Richese declaration', () => {
|
||
const native = [richese('r-yes',4,true),richese('r-no',9,false)];
|
||
const all = [phase('p-yes',7,true),phase('p-no',8,false)];
|
||
const before = structuredClone({native,all});
|
||
assert.deepEqual(jointRicheseBidCompletionRange(native,all,opportunity),{minimum:7,maximum:7});
|
||
assert.deepEqual({native,all},before,'A quote cannot mutate either actual ledger');
|
||
assert.equal(jointRicheseBidCompletionRange(native,[...all,phase('contradiction',7,false)],opportunity),null);
|
||
});
|
||
|
||
void test('a separately witnessed future phase Yes does not relax current No caps', () => {
|
||
const native = [richese('current-yes',3,true)];
|
||
const all = [phase('later-yes',7,true),phase('all-no',6,false)];
|
||
assert.equal(jointRicheseBidCompletionRange(native,all,opportunity),null);
|
||
assert.deepEqual(jointRicheseBidCompletionRange(native,all,opportunity,{includePhaseYes:false}),
|
||
{minimum:3,maximum:5});
|
||
});
|
||
|
||
void test('only this bidder’s live phase bounds enter the original event without ID collisions', () => {
|
||
const native = [richese('phase-any:live',2,false)];
|
||
const all = [phase('live',5,false),{...phase('other',1,true),player:'q'},
|
||
{...phase('earlier',1,true),turn:1},{...phase('fulfilled',1,true),fulfilled:true},
|
||
{...phase('released',1,true),released:true}];
|
||
const rows = richeseBidsWithPhaseBounds(native,all,opportunity);
|
||
assert.equal(rows.length,2);
|
||
assert.equal(rows[0],native[0]);
|
||
assert.notEqual(rows[1].id,native[0].id);
|
||
assert.deepEqual({...rows[1],id:'synthetic'},
|
||
{id:'synthetic',turn:2,event:'lot',player:'p',asker:'a',minimum:5,answer:false});
|
||
assert.deepEqual(jointRicheseBidCompletionRange([],all,opportunity),{minimum:2,maximum:4});
|
||
});
|
||
|
||
void test('a synthetic bound requires the actual bidder, turn and lot event', () => {
|
||
assert.throws(() => richeseBidsWithPhaseBounds([],[],{...opportunity,event:''}));
|
||
assert.throws(() => richeseBidsWithPhaseBounds([],[],{...opportunity,player:' p'}));
|
||
assert.throws(() => richeseBidsWithPhaseBounds([],[],{...opportunity,turn:0}));
|
||
});
|