From 01660b4c6ac5d451102d73a7df22483f9fcc2ea1 Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Mon, 1 Dec 2025 17:16:38 +0100 Subject: complete operations sequence tests --- pbt/ts/src/bank.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'pbt/ts/src/bank.ts') diff --git a/pbt/ts/src/bank.ts b/pbt/ts/src/bank.ts index e5619f4..e388354 100644 --- a/pbt/ts/src/bank.ts +++ b/pbt/ts/src/bank.ts @@ -1,4 +1,4 @@ -import {Option, fromNullable} from 'fp-ts/lib/Option'; +import {Option, fromNullable, isSome, matchW} from 'fp-ts/lib/Option'; // keep it simple export type Account = string; @@ -32,11 +32,27 @@ export class SimpleBank implements Bank { } deposit(account: Account, amt: number): void { - throw new Error('Method not implemented.'); + const current = this.balance(account); + matchW( + () => { + throw new Error(`Unknown account ${account}`); + }, + (bal: number) => { + this.accounts.set(account, bal + amt); + }, + )(current); } withdraw(account: Account, amt: number): void { - throw new Error('Method not implemented.'); + const current = this.balance(account); + matchW( + () => { + throw new Error(`Unknown account ${account}`); + }, + (bal: number) => { + this.accounts.set(account, bal - amt); + }, + )(current); } } -- cgit v1.3.1