diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2026-08-30 18:08:55 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2026-09-01 07:58:04 +0200 |
| commit | b3285b3f5878d705fcbeb7165097b6623a02f553 (patch) | |
| tree | 6b08a1eb2e88eb0406979642c7f2b61547815fa8 /pbt/ts/src/bank.test.ts | |
| parent | 966f532a61b34d187bfdeefed7617fbfb6f768ed (diff) | |
| download | lambda-nantes-b3285b3f5878d705fcbeb7165097b6623a02f553.tar.gz | |
Replace jest with vitest
This implies fixing some quirky modules import logic. Thanks to Claude
for fixing this whole s**t
Diffstat (limited to 'pbt/ts/src/bank.test.ts')
| -rw-r--r-- | pbt/ts/src/bank.test.ts | 124 |
1 files changed, 60 insertions, 64 deletions
diff --git a/pbt/ts/src/bank.test.ts b/pbt/ts/src/bank.test.ts index 021e4c6..a6b3e76 100644 --- a/pbt/ts/src/bank.test.ts +++ b/pbt/ts/src/bank.test.ts @@ -1,10 +1,10 @@ -import {toNullable} from 'fp-ts/lib/Option'; +import {toNullable} from 'fp-ts/lib/Option.js'; import { Account, Operation, SimpleBank, bankImplementationMatchesModel, -} from './bank'; +} from './bank.js'; import { Gen, Property, @@ -16,10 +16,11 @@ import { listOf, mapOf1 as nonEmptyMap, property, -} from './property'; +} from './property.js'; import Prando from 'prando'; -import {LevelBank} from './levelbank'; -import {withTempFile} from './fs'; +import {LevelBank} from './levelbank.js'; +import {withTempFile} from './fs.js'; +import {test, expect} from 'vitest'; const sampleAccounts: Account[] = [ 'FR12345678901234', @@ -116,83 +117,78 @@ const levelBankMatchFakeBank = return true; }; -describe('Bank Simulator', () => { - test('level-db bank conforms to model', async () => { - const prop = forall(genAccounts, async accounts => { - return property(genOperations(accounts), async ops => { - const levelBank = await withTempFile( - filename => new LevelBank(filename), - ).then(bank => bank.populateWith(accounts)); +test('level-db bank conforms to model', async () => { + const prop = forall(genAccounts, async accounts => { + return property(genOperations(accounts), async ops => { + const levelBank = await withTempFile( + filename => new LevelBank(filename), + ).then(bank => bank.populateWith(accounts)); - return bankImplementationMatchesModel(accounts)(levelBank)(ops); - }); + return bankImplementationMatchesModel(accounts)(levelBank)(ops); }); + }); - const result = await Property.run(prop); + const result = await Property.run(prop); - console.log(result); - console.log(JSON.stringify(result.counterexample)); + console.log(result); + console.log(JSON.stringify(result.counterexample)); - expect(result.result).toBe('OK'); - }); + expect(result.result).toBe('OK'); +}); - // - // - // - // - // - // +// +// +// +// +// +// - test('in-mem bank conforms to model', async () => { - const prop = forall(genAccounts, async accounts => { - return property(genOperations(accounts), async ops => { - const simpleBank = new SimpleBank(accounts); +test('in-mem bank conforms to model', async () => { + const prop = forall(genAccounts, async accounts => { + return property(genOperations(accounts), async ops => { + const simpleBank = new SimpleBank(accounts); - return bankImplementationMatchesModel(accounts)(simpleBank)(ops); - }); + return bankImplementationMatchesModel(accounts)(simpleBank)(ops); }); + }); - const result = await Property.run(prop); + const result = await Property.run(prop); - console.log(result); - console.log(JSON.stringify(result.counterexample)); + console.log(result); + console.log(JSON.stringify(result.counterexample)); - expect(result.result).toBe('OK'); - }); + expect(result.result).toBe('OK'); +}); - // - // - // - // - // - // +// +// +// +// +// +// - test('can retrieve balance given account exists', async () => { - const prop = forall(genAccounts, async accounts => { - const api = new SimpleBank(accounts); - return property(keyValueOf(accounts), async ([accountNr, bal]) => { - const retrieved = toNullable(await api.balance(accountNr)); - return Promise.resolve(retrieved === bal); - }); +test('can retrieve balance given account exists', async () => { + const prop = forall(genAccounts, async accounts => { + const api = new SimpleBank(accounts); + return property(keyValueOf(accounts), async ([accountNr, bal]) => { + const retrieved = toNullable(await api.balance(accountNr)); + return Promise.resolve(retrieved === bal); }); - - const result = await Property.run(prop); - - expect(result.result).toBe('OK'); }); - test('correctly update balance given a sequence of deposits and withdrawals', async () => { - const prop = forall(genAccounts, accounts => { - return property( - genOperations(accounts), - levelBankMatchFakeBank(accounts), - ); - }); + const result = await Property.run(prop); - const result = await Property.run(prop); + expect(result.result).toBe('OK'); +}); - console.log(result); - console.log(JSON.stringify(result.counterexample)); - expect(result.result).toBe('OK'); +test('correctly update balance given a sequence of deposits and withdrawals', async () => { + const prop = forall(genAccounts, accounts => { + return property(genOperations(accounts), levelBankMatchFakeBank(accounts)); }); + + const result = await Property.run(prop); + + console.log(result); + console.log(JSON.stringify(result.counterexample)); + expect(result.result).toBe('OK'); }); |
