-
-
Notifications
You must be signed in to change notification settings - Fork 633
/
Copy pathproof.ci.js
55 lines (46 loc) · 923 Bytes
/
proof.ci.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
export class BankAccount {
open() {
if (this._open) {
throw new ValueError();
}
this._open = true;
this._balance = 0;
}
close() {
this.verifyAccount();
this._open = false;
}
verifyAccount() {
if (!this.isOpen) {
throw new ValueError();
}
}
deposit(amount) {
this.verifyAccount();
this.verifyDeposit(amount);
this._balance = this._balance + amount;
}
verifyDeposit(amount) {
if (amount < 0) {
throw new ValueError();
}
}
withdraw(amount) {
this.verifyAccount();
this.verifyWithdraw(amount);
this._balance = this._balance - amount;
}
verifyWithdraw(amount) {
if (amount < 0 || amount > this._balance) {
throw new ValueError();
}
}
get balance() {
this.verifyAccount();
return this._balance;
}
get isOpen() {
return this._open;
}
}
export class ValueError extends Error {}