diff options
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'); + }); +}); |
