1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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');
});
});
|