Files
CONSOLGAMES/tests/sim/economy.test.ts
T

46 lines
1.6 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import {
customerMinimumAsk, MONTHLY_RENT_CENTS, priceOf, purchaseProbability,
referencePrice, wholesaleCost,
} from '../../src/sim/economy';
import { getGame } from '../../src/sim/catalog';
import { testCatalog } from './helpers';
const catalog = testCatalog();
const sml = getGame(catalog, 'sml'); // 3796 cents
describe('economy', () => {
it('buys from the wholesaler at 65% of launch price', () => {
expect(wholesaleCost(sml)).toBe(2467);
});
it('derives used reference prices from the condition', () => {
expect(referencePrice(sml, 'new')).toBe(3796);
expect(referencePrice(sml, 'complete')).toBe(2278);
expect(referencePrice(sml, 'no_manual')).toBe(1898);
expect(referencePrice(sml, 'loose')).toBe(1518);
});
it('maps price ratio to purchase probability', () => {
expect(purchaseProbability(1000, 1000)).toBeCloseTo(0.5);
expect(purchaseProbability(500, 1000)).toBe(1);
expect(purchaseProbability(1500, 1000)).toBe(0);
expect(purchaseProbability(3000, 1000)).toBe(0);
});
it('computes what a customer accepts for a buy-back', () => {
expect(customerMinimumAsk(sml, 'complete', 'cash')).toBe(797);
expect(customerMinimumAsk(sml, 'complete', 'trade')).toBe(1139);
});
it('uses the player price, else the reference price', () => {
const item = { gameId: 'sml', condition: 'new' as const };
expect(priceOf({}, catalog, item)).toBe(3796);
expect(priceOf({ 'sml|new': 3500 }, catalog, item)).toBe(3500);
});
it('charges 6000 F of rent per month', () => {
expect(MONTHLY_RENT_CENTS).toBe(91469);
});
});