From a8c27de3f4434d8a08e953b95b47a4161f9473ed Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Sat, 29 Nov 2025 09:07:09 +0100 Subject: start simple bank example --- pbt/ts/src/bank.test.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 pbt/ts/src/bank.test.ts (limited to 'pbt/ts/src/bank.test.ts') diff --git a/pbt/ts/src/bank.test.ts b/pbt/ts/src/bank.test.ts new file mode 100644 index 0000000..9ec25c0 --- /dev/null +++ b/pbt/ts/src/bank.test.ts @@ -0,0 +1,42 @@ +import {toNullable} from 'fp-ts/lib/Option'; +import {Account, SimpleBank} from './bank'; +import { + Gen, + Property, + choose, + elements, + forall, + keyValueOf, + mapOf, + mapOf1, + property, +} from './property'; + +const sampleAccounts: Account[] = [ + 'FR12345678901234', + 'DE2345678901234', + 'IT34567890123412', +]; + +const genAccount: Gen = elements(sampleAccounts); + +const genBalance: Gen = choose(0, 1000000); + +const genAccounts: Gen> = mapOf1(genAccount, genBalance); + +describe('Bank Simulator', () => { + test('can retrieve balance given account exists', () => { + const prop = forall(genAccounts, accounts => { + const api = new SimpleBank(accounts); + return property(keyValueOf(accounts), ([accountNr, bal]) => { + const retrieved = toNullable(api.balance(accountNr)); + return retrieved == bal; + }); + }); + + const result = Property.run(prop); + + console.log(result); + expect(result.result).toBe('OK'); + }); +}); -- cgit v1.3.1