forked from unimatrix/web
32 lines
2.6 KiB
JavaScript
32 lines
2.6 KiB
JavaScript
import test from 'node:test';import assert from 'node:assert/strict';
|
|
import {ladderFare,effectiveTrips,reducedFare,paidTariff,classifyRoute,TRAVEL_BASE_MINOR,TRAVEL_CAP_MINOR,TRAVEL_RESET_MS,BOUNTY_MULTIPLIER} from '../node/travel-tariff.mjs';
|
|
test('the ladder starts at 150 DM and compounds 10% per paid trip',()=>{
|
|
assert.equal(ladderFare(0),15000);assert.equal(ladderFare(1),16500);assert.equal(ladderFare(2),18150);assert.equal(ladderFare(3),19965);
|
|
for(let i=0;i<60;i++)assert.ok(ladderFare(i+1)>=ladderFare(i));
|
|
});
|
|
test('the ladder never exceeds 5000 DM and stays there',()=>{
|
|
assert.equal(ladderFare(1000),TRAVEL_CAP_MINOR);assert.equal(ladderFare(1e9),TRAVEL_CAP_MINOR);
|
|
let first=0;while(ladderFare(first)<TRAVEL_CAP_MINOR)first++;assert.equal(ladderFare(first-1)<TRAVEL_CAP_MINOR,true);assert.equal(ladderFare(first+1),TRAVEL_CAP_MINOR);
|
|
});
|
|
test('the counter resets after thirty days without a paid trip',()=>{
|
|
const now=10*TRAVEL_RESET_MS;
|
|
assert.equal(effectiveTrips(7,now-TRAVEL_RESET_MS+1,now),7);assert.equal(effectiveTrips(7,now-TRAVEL_RESET_MS,now),0);assert.equal(effectiveTrips(7,null,now),0);
|
|
});
|
|
test('a clan or company on the destination halves the fare and the bounty',()=>{
|
|
const full=paidTariff({trips:0,reduced:false}),half=paidTariff({trips:0,reduced:true});
|
|
assert.equal(full.fareMinor,15000);assert.equal(full.bountyMinor,75000);assert.equal(half.fareMinor,7500);assert.equal(half.bountyMinor,37500);
|
|
assert.equal(half.bountyMinor*2,full.bountyMinor);assert.equal(full.bountyMinor,TRAVEL_BASE_MINOR*BOUNTY_MULTIPLIER);
|
|
});
|
|
test('the bounty is five times the fare actually paid, at every step',()=>{
|
|
for(const trips of [0,1,5,40,500])for(const reduced of [false,true]){const t=paidTariff({trips,reduced});assert.equal(t.bountyMinor,t.fareMinor*5);assert.ok(t.fareMinor>=1);}
|
|
assert.equal(reducedFare(1),1);assert.equal(reducedFare(15001),7501);
|
|
});
|
|
test('lobby, the race world and decrees are free; every other world is paid',()=>{
|
|
assert.deepEqual(classifyRoute({destination:'lobby',raceWorld:'caladan'}),{free:true,reason:'lobby'});
|
|
assert.deepEqual(classifyRoute({destination:'caladan',raceWorld:'caladan'}),{free:true,reason:'race-world'});
|
|
assert.deepEqual(classifyRoute({destination:'arrakis',raceWorld:'caladan',decree:true}),{free:true,reason:'decree'});
|
|
assert.deepEqual(classifyRoute({destination:'arrakis',raceWorld:'caladan'}),{free:false,reason:'paid'});
|
|
});
|
|
test('invalid input is rejected instead of producing a fare',()=>{
|
|
assert.throws(()=>ladderFare(-1),RangeError);assert.throws(()=>ladderFare(1.5),RangeError);assert.throws(()=>effectiveTrips(-1,0,0),RangeError);
|
|
});
|

Staff