Finished
1import { describe, it } from 'node:test';
2import assert from 'node:assert/strict';
3import { BankAccount, ValueError } from './main.js';
4
5describe('BankAccount', () => {
6 it('should open an account', () => {
7 const account = new BankAccount();
8 account.open();
9 assert.strictEqual(account.balance, 0);
10 });
11
12 it('should not open an already opened account', () => {
13 const account = new BankAccount();
14 account.open();
15 assert.throws(() => account.open(), ValueError);
16 });
17
18 it('should close an account', () => {
19 const account = new BankAccount();
20 account.open();
21 account.close();
22 assert.throws(() => account.balance, ValueError);
23 });
24
25 it('should not close an already closed account', () => {
26 const account = new BankAccount();
27 account.open();
28 account.close();
29 assert.throws(() => account.close(), ValueError);
30 });
31
32 it('should deposit money', () => {
33 const account = new BankAccount();
34 account.open();
35 account.deposit(100);
36 assert.strictEqual(account.balance, 100);
37 });
38
39 it('should not deposit negative amount', () => {
40 const account = new BankAccount();
41 account.open();
42 assert.throws(() => account.deposit(-50), ValueError);
43 });
44
45 it('should not deposit to a closed account', () => {
46 const account = new BankAccount();
47 account.open();
48 account.close();
49 assert.throws(() => account.deposit(50), ValueError);
50 });
51
52 it('should withdraw money', () => {
53 const account = new BankAccount();
54 account.open();
55 account.deposit(100);
56 account.withdraw(50);
57 assert.strictEqual(account.balance, 50);
58 });
59
60 it('should not withdraw negative amount', () => {
61 const account = new BankAccount();
62 account.open();
63 account.deposit(100);
64 assert.throws(() => account.withdraw(-50), ValueError);
65 });
66
67 it('should not withdraw more than balance', () => {
68 const account = new BankAccount();
69 account.open();
70 account.deposit(50);
71 assert.throws(() => account.withdraw(100), ValueError);
72 });
73
74 it('should not withdraw from a closed account', () => {
75 const account = new BankAccount();
76 account.open();
77 account.deposit(50);
78 account.close();
79 assert.throws(() => account.withdraw(25), ValueError);
80 });
81
82 it('should handle multiple deposits', () => {
83 const account = new BankAccount();
84 account.open();
85 account.deposit(50);
86 account.deposit(75);
87 assert.strictEqual(account.balance, 125);
88 });
89
90 it('should handle multiple withdrawals', () => {
91 const account = new BankAccount();
92 account.open();
93 account.deposit(100);
94 account.withdraw(25);
95 account.withdraw(30);
96 assert.strictEqual(account.balance, 45);
97 });
98
99 it('should handle deposit and withdrawal combinations', () => {
100 const account = new BankAccount();
101 account.open();
102 account.deposit(100);
103 account.withdraw(50);
104 account.deposit(25);
105 account.withdraw(30);
106 assert.strictEqual(account.balance, 45);
107 });
108});
Test NameStatus
newly opened account has zero balance
Fail
Single deposit
Fail
Multiple deposits"
Fail
Withdraw once
Fail
Withdraw twice
Fail
Can do multiple operations sequentially
Fail
Cannot deposit into closed account
Fail
Cannot deposit into unopened account
Fail
Cannot withdraw from closed account
Fail
Cannot close an account that was not opened
Fail
Cannot open an already opened account
Fail
Reopened account does not retain balance
Fail
Cannot withdraw more than deposited
Fail
Cannot withdraw negative
Fail
Cannot deposit negative
Fail
Cannot check balance of closed account
Pass
Can handle concurrent transactions
Pass
Changing balance directly throws error
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.