diff options
Diffstat (limited to 'pbt/ts/src')
| -rw-r--r-- | pbt/ts/src/bank.test.ts | 24 | ||||
| -rw-r--r-- | pbt/ts/src/bank.ts | 31 | ||||
| -rw-r--r-- | pbt/ts/src/index.test.ts | 3 |
3 files changed, 58 insertions, 0 deletions
diff --git a/pbt/ts/src/bank.test.ts b/pbt/ts/src/bank.test.ts index 3b40573..021e4c6 100644 --- a/pbt/ts/src/bank.test.ts +++ b/pbt/ts/src/bank.test.ts @@ -143,6 +143,30 @@ describe('Bank Simulator', () => { // // + 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); + }); + }); + + const result = await Property.run(prop); + + console.log(result); + console.log(JSON.stringify(result.counterexample)); + + expect(result.result).toBe('OK'); + }); + + // + // + // + // + // + // + test('can retrieve balance given account exists', async () => { const prop = forall(genAccounts, async accounts => { const api = new SimpleBank(accounts); diff --git a/pbt/ts/src/bank.ts b/pbt/ts/src/bank.ts index bf14e43..6a220dc 100644 --- a/pbt/ts/src/bank.ts +++ b/pbt/ts/src/bank.ts @@ -1,3 +1,24 @@ +/// Demystify Property-Based Testing +/// +/// Arnaud Bailly +/// +/// @abailly.bsky.social - @abailly@piaille.fr - @dr_c0d3 (X) +/// +/// https://www.linkedin.com/in/arnaudbailly/ +/// +/// https://abailly.github.io +/// +/// An experiment and an experience +/// +/// https://app.radicle.xyz/nodes/seed.hydra.bzh/rad:z28SSH7hyCTu387guFhtPXYxcwtUs/tree/pbt/README.md +/// +/// 1. Introduction +/// +/// 2. Real world use cases +/// +/// 3. Developing a mini-quickcheck from a "concrete" use case +/// + import {Option, fromNullable, matchW, toNullable} from 'fp-ts/lib/Option'; // keep it simple @@ -143,6 +164,16 @@ export const bankImplementationMatchesModel = return true; }; +// +// +// +// +// +// +// + +/// A "simulation" of Bank interface for integration testing purpose. +/// This export class SimpleBank implements Bank { private accounts: Map<Account, number>; diff --git a/pbt/ts/src/index.test.ts b/pbt/ts/src/index.test.ts index f3a51e1..675f683 100644 --- a/pbt/ts/src/index.test.ts +++ b/pbt/ts/src/index.test.ts @@ -9,8 +9,11 @@ describe('testing lists reversal', () => { const reverse_append_result = await Property.run( prop_reverse_with_two_lists, ); + console.log(reverse_append_result); + console.log(reverse_append_result.counterexample); expect(reverse_append_result.result).toBe('OK'); }); + test('reverse is self-inverse', async () => { const result = await Property.run(prop_reverse_is_self_inverse); console.log(classify(result)); |
