Skip to content

Commit e552175

Browse files
Add bank-account tests.toml (#159)
1 parent 4422525 commit e552175

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

exercises/practice/bank-account/.docs/instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Your task is to implement bank accounts supporting opening/closing, withdrawals, and deposits of money.
44

55
As bank accounts can be accessed in many different ways (internet, mobile phones, automatic charges), your bank software must allow accounts to be safely accessed from multiple threads/processes (terminology depends on your programming language) in parallel.
6-
For example, there may be many deposits and withdrawals occurring in parallel; you need to ensure there is no [race conditions][wikipedia] between when you read the account balance and set the new balance.
6+
For example, there may be many deposits and withdrawals occurring in parallel; you need to ensure there are no [race conditions][wikipedia] between when you read the account balance and set the new balance.
77

88
It should be possible to close an account; operations against a closed account must fail.
99

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[983a1528-4ceb-45e5-8257-8ce01aceb5ed]
13+
description = "Newly opened account has zero balance"
14+
15+
[e88d4ec3-c6bf-4752-8e59-5046c44e3ba7]
16+
description = "Single deposit"
17+
18+
[3d9147d4-63f4-4844-8d2b-1fee2e9a2a0d]
19+
description = "Multiple deposits"
20+
21+
[08f1af07-27ae-4b38-aa19-770bde558064]
22+
description = "Withdraw once"
23+
24+
[6f6d242f-8c31-4ac6-8995-a90d42cad59f]
25+
description = "Withdraw twice"
26+
27+
[45161c94-a094-4c77-9cec-998b70429bda]
28+
description = "Can do multiple operations sequentially"
29+
30+
[f9facfaa-d824-486e-8381-48832c4bbffd]
31+
description = "Cannot check balance of closed account"
32+
33+
[7a65ba52-e35c-4fd2-8159-bda2bde6e59c]
34+
description = "Cannot deposit into closed account"
35+
36+
[a0a1835d-faae-4ad4-a6f3-1fcc2121380b]
37+
description = "Cannot deposit into unopened account"
38+
39+
[570dfaa5-0532-4c1f-a7d3-0f65c3265608]
40+
description = "Cannot withdraw from closed account"
41+
42+
[c396d233-1c49-4272-98dc-7f502dbb9470]
43+
description = "Cannot close an account that was not opened"
44+
45+
[c06f534f-bdc2-4a02-a388-1063400684de]
46+
description = "Cannot open an already opened account"
47+
48+
[0722d404-6116-4f92-ba3b-da7f88f1669c]
49+
description = "Reopened account does not retain balance"
50+
51+
[ec42245f-9361-4341-8231-a22e8d19c52f]
52+
description = "Cannot withdraw more than deposited"
53+
54+
[4f381ef8-10ef-4507-8e1d-0631ecc8ee72]
55+
description = "Cannot withdraw negative"
56+
57+
[d45df9ea-1db0-47f3-b18c-d365db49d938]
58+
description = "Cannot deposit negative"
59+
60+
[ba0c1e0b-0f00-416f-8097-a7dfc97871ff]
61+
description = "Can handle concurrent transactions"
62+
include = false

exercises/practice/bank-account/bank-account.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ describe("Bank Account", () => {
6868
expect(account.balance()).toEqual(0);
6969
});
7070

71+
xtest("can do multiple operations sequentially", () => {
72+
const account = currentInstance.exports;
73+
expect(account.open()).toEqual(0);
74+
expect(account.deposit(100)).toEqual(0);
75+
expect(account.deposit(110)).toEqual(0);
76+
expect(account.withdraw(200)).toEqual(0);
77+
expect(account.deposit(60)).toEqual(0);
78+
expect(account.withdraw(50)).toEqual(0);
79+
expect(account.balance()).toEqual(20);
80+
});
81+
7182
xtest("checking balance of closed account throws error", () => {
7283
const account = currentInstance.exports;
7384
expect(account.open()).toEqual(0);
@@ -82,13 +93,23 @@ describe("Bank Account", () => {
8293
expect(account.deposit(50)).toEqual(-1);
8394
});
8495

96+
xtest("deposit into unopened account throws error", () => {
97+
const account = currentInstance.exports;
98+
expect(account.deposit(50)).toEqual(-1);
99+
});
100+
85101
xtest("withdraw from closed account throws error", () => {
86102
const account = currentInstance.exports;
87103
expect(account.open()).toEqual(0);
88104
expect(account.close()).toEqual(0);
89105
expect(account.withdraw(50)).toEqual(-1);
90106
});
91107

108+
xtest("close unopened account throws error", () => {
109+
const account = currentInstance.exports;
110+
expect(account.close()).toEqual(-1);
111+
});
112+
92113
xtest("close already closed account throws error", () => {
93114
const account = currentInstance.exports;
94115
expect(account.close()).toEqual(-1);

0 commit comments

Comments
 (0)