Files
Dune/tests/truthtrance-freeform-facts.test.ts
T
Quintine 8ae275f598
Verify and publish checkpoint container / container (push) Successful in 10m38s
Interpret bounded Truthtrance fact questions
2026-10-29 04:31:15 +11:00

35 lines
2.0 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { parseFreeformFactV1 } from '../game/truthtrance-freeform-facts';
import { TRUTH_CARD_NAMES } from '../game/truthtrance-card-names';
void test('freeform v1 compiles exact current personal spice comparisons', () => {
assert.deepEqual(parseFreeformFactV1('Do you have at least 5 spice?'), {kind:'spice', compare:'gte', value:5});
assert.deepEqual(parseFreeformFactV1(' DO YOU HAVE EXACTLY 0 SPICE '), {kind:'spice', compare:'eq', value:0});
assert.deepEqual(parseFreeformFactV1('do you have at most 7 spice'), {kind:'spice', compare:'lte', value:7});
assert.deepEqual(parseFreeformFactV1('Do\tyou have at\tleast 0002 spice?'), {kind:'spice', compare:'gte', value:2});
assert.equal(parseFreeformFactV1('Do you have exactly 9007199254740992 spice?'), null);
});
void test('freeform v1 resolves only exact printed card names regardless of case', () => {
for (const name of TRUTH_CARD_NAMES) {
assert.deepEqual(parseFreeformFactV1(`do you have a ${name.toUpperCase()}?`), {kind:'hand', name});
}
assert.deepEqual(parseFreeformFactV1('Do you have an Artillery Strike?'), {kind:'hand', name:'Artillery Strike'});
assert.equal(parseFreeformFactV1('Do you have a shield card?'), null);
assert.equal(parseFreeformFactV1('Do you have a secret weapon?'), null);
});
void test('freeform v1 declines ambiguous, compound, negative and future wording', () => {
for (const phrase of [
'', 'Do you have 5 spice?', 'Do you have more than 5 spice?',
'Do you have at least -1 spice?', 'Do you have at least 2.5 spice?',
'Do you have at least 5 spice and a Shield?',
'Do you not have a Shield?', 'Do you have a Shield or a Snooper?',
'Do you have a Shield this turn?', 'Will you have at least 5 spice?',
'Do you have a Shield??', 'Do you have a Shield? Please answer.',
'Do you have at least 5 spice?\nOr a Shield?',
'Do you have a Shield?'.padEnd(501, ' '),
]) assert.equal(parseFreeformFactV1(phrase), null, phrase);
});