diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-29 09:07:09 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-29 09:07:09 +0100 |
| commit | a8c27de3f4434d8a08e953b95b47a4161f9473ed (patch) | |
| tree | 426e6840756dc40881a6bb7384e7f7107e3a2d88 /pbt/ts/src/bank.test.ts | |
| parent | 97e0dfa41a50d9b7af7d1769e2e712625efb3175 (diff) | |
| download | lambda-nantes-a8c27de3f4434d8a08e953b95b47a4161f9473ed.tar.gz | |
start simple bank example
Diffstat (limited to 'pbt/ts/src/bank.test.ts')
| -rw-r--r-- | pbt/ts/src/bank.test.ts | 42 |
1 files changed, 42 insertions, 0 deletions
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<Account> = elements(sampleAccounts); + +const genBalance: Gen<number> = choose(0, 1000000); + +const genAccounts: Gen<Map<Account, number>> = 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'); + }); +}); |
