|
| 1 | +{ |
| 2 | + "exercise": "bank-account", |
| 3 | + "comments": [ |
| 4 | + "This exercise is a good candidate to practice concurrency, which", |
| 5 | + "may not be available or possible in the implementing language track.", |
| 6 | + "It is possible to implement this exercise without concurrency." |
| 7 | + ], |
| 8 | + "cases": [ |
| 9 | + { |
| 10 | + "uuid": "983a1528-4ceb-45e5-8257-8ce01aceb5ed", |
| 11 | + "description": "Newly opened account has zero balance", |
| 12 | + "property": "bankAccount", |
| 13 | + "input": { |
| 14 | + "operations": [ |
| 15 | + { |
| 16 | + "operation": "open" |
| 17 | + }, |
| 18 | + { |
| 19 | + "operation": "balance" |
| 20 | + } |
| 21 | + ] |
| 22 | + }, |
| 23 | + "expected": 0 |
| 24 | + }, |
| 25 | + { |
| 26 | + "uuid": "e88d4ec3-c6bf-4752-8e59-5046c44e3ba7", |
| 27 | + "description": "Single deposit", |
| 28 | + "property": "bankAccount", |
| 29 | + "input": { |
| 30 | + "operations": [ |
| 31 | + { |
| 32 | + "operation": "open" |
| 33 | + }, |
| 34 | + { |
| 35 | + "operation": "deposit", |
| 36 | + "amount": 100 |
| 37 | + }, |
| 38 | + { |
| 39 | + "operation": "balance" |
| 40 | + } |
| 41 | + ] |
| 42 | + }, |
| 43 | + "expected": 100 |
| 44 | + }, |
| 45 | + { |
| 46 | + "uuid": "3d9147d4-63f4-4844-8d2b-1fee2e9a2a0d", |
| 47 | + "description": "Multiple deposits", |
| 48 | + "property": "bankAccount", |
| 49 | + "input": { |
| 50 | + "operations": [ |
| 51 | + { |
| 52 | + "operation": "open" |
| 53 | + }, |
| 54 | + { |
| 55 | + "operation": "deposit", |
| 56 | + "amount": 100 |
| 57 | + }, |
| 58 | + { |
| 59 | + "operation": "deposit", |
| 60 | + "amount": 50 |
| 61 | + }, |
| 62 | + { |
| 63 | + "operation": "balance" |
| 64 | + } |
| 65 | + ] |
| 66 | + }, |
| 67 | + "expected": 150 |
| 68 | + }, |
| 69 | + { |
| 70 | + "uuid": "08f1af07-27ae-4b38-aa19-770bde558064", |
| 71 | + "description": "Withdraw once", |
| 72 | + "property": "bankAccount", |
| 73 | + "input": { |
| 74 | + "operations": [ |
| 75 | + { |
| 76 | + "operation": "open" |
| 77 | + }, |
| 78 | + { |
| 79 | + "operation": "deposit", |
| 80 | + "amount": 100 |
| 81 | + }, |
| 82 | + { |
| 83 | + "operation": "withdraw", |
| 84 | + "amount": 75 |
| 85 | + }, |
| 86 | + { |
| 87 | + "operation": "balance" |
| 88 | + } |
| 89 | + ] |
| 90 | + }, |
| 91 | + "expected": 25 |
| 92 | + }, |
| 93 | + { |
| 94 | + "uuid": "6f6d242f-8c31-4ac6-8995-a90d42cad59f", |
| 95 | + "description": "Withdraw twice", |
| 96 | + "property": "bankAccount", |
| 97 | + "input": { |
| 98 | + "operations": [ |
| 99 | + { |
| 100 | + "operation": "open" |
| 101 | + }, |
| 102 | + { |
| 103 | + "operation": "deposit", |
| 104 | + "amount": 100 |
| 105 | + }, |
| 106 | + { |
| 107 | + "operation": "withdraw", |
| 108 | + "amount": 80 |
| 109 | + }, |
| 110 | + { |
| 111 | + "operation": "withdraw", |
| 112 | + "amount": 20 |
| 113 | + }, |
| 114 | + { |
| 115 | + "operation": "balance" |
| 116 | + } |
| 117 | + ] |
| 118 | + }, |
| 119 | + "expected": 0 |
| 120 | + }, |
| 121 | + { |
| 122 | + "uuid": "45161c94-a094-4c77-9cec-998b70429bda", |
| 123 | + "description": "Can do multiple operations sequentially", |
| 124 | + "property": "bankAccount", |
| 125 | + "input": { |
| 126 | + "operations": [ |
| 127 | + { |
| 128 | + "operation": "open" |
| 129 | + }, |
| 130 | + { |
| 131 | + "operation": "deposit", |
| 132 | + "amount": 100 |
| 133 | + }, |
| 134 | + { |
| 135 | + "operation": "deposit", |
| 136 | + "amount": 110 |
| 137 | + }, |
| 138 | + { |
| 139 | + "operation": "withdraw", |
| 140 | + "amount": 200 |
| 141 | + }, |
| 142 | + { |
| 143 | + "operation": "deposit", |
| 144 | + "amount": 60 |
| 145 | + }, |
| 146 | + { |
| 147 | + "operation": "withdraw", |
| 148 | + "amount": 50 |
| 149 | + }, |
| 150 | + { |
| 151 | + "operation": "balance" |
| 152 | + } |
| 153 | + ] |
| 154 | + }, |
| 155 | + "expected": 20 |
| 156 | + }, |
| 157 | + { |
| 158 | + "uuid": "f9facfaa-d824-486e-8381-48832c4bbffd", |
| 159 | + "description": "Cannot check balance of closed account", |
| 160 | + "property": "bankAccount", |
| 161 | + "input": { |
| 162 | + "operations": [ |
| 163 | + { |
| 164 | + "operation": "open" |
| 165 | + }, |
| 166 | + { |
| 167 | + "operation": "close" |
| 168 | + }, |
| 169 | + { |
| 170 | + "operation": "balance" |
| 171 | + } |
| 172 | + ] |
| 173 | + }, |
| 174 | + "expected": { "error": "account not open" } |
| 175 | + }, |
| 176 | + { |
| 177 | + "uuid": "7a65ba52-e35c-4fd2-8159-bda2bde6e59c", |
| 178 | + "description": "Cannot deposit into closed account", |
| 179 | + "property": "bankAccount", |
| 180 | + "input": { |
| 181 | + "operations": [ |
| 182 | + { |
| 183 | + "operation": "open" |
| 184 | + }, |
| 185 | + { |
| 186 | + "operation": "close" |
| 187 | + }, |
| 188 | + { |
| 189 | + "operation": "deposit", |
| 190 | + "amount": 50 |
| 191 | + } |
| 192 | + ] |
| 193 | + }, |
| 194 | + "expected": { "error": "account not open" } |
| 195 | + }, |
| 196 | + { |
| 197 | + "uuid": "a0a1835d-faae-4ad4-a6f3-1fcc2121380b", |
| 198 | + "description": "Cannot deposit into unopened account", |
| 199 | + "property": "bankAccount", |
| 200 | + "input": { |
| 201 | + "operations": [ |
| 202 | + { |
| 203 | + "operation": "deposit", |
| 204 | + "amount": 50 |
| 205 | + } |
| 206 | + ] |
| 207 | + }, |
| 208 | + "expected": { "error": "account not open" } |
| 209 | + }, |
| 210 | + { |
| 211 | + "uuid": "570dfaa5-0532-4c1f-a7d3-0f65c3265608", |
| 212 | + "description": "Cannot withdraw from closed account", |
| 213 | + "property": "bankAccount", |
| 214 | + "input": { |
| 215 | + "operations": [ |
| 216 | + { |
| 217 | + "operation": "open" |
| 218 | + }, |
| 219 | + { |
| 220 | + "operation": "close" |
| 221 | + }, |
| 222 | + { |
| 223 | + "operation": "withdraw", |
| 224 | + "amount": 50 |
| 225 | + } |
| 226 | + ] |
| 227 | + }, |
| 228 | + "expected": { "error": "account not open" } |
| 229 | + }, |
| 230 | + { |
| 231 | + "uuid": "c396d233-1c49-4272-98dc-7f502dbb9470", |
| 232 | + "description": "Cannot close an account that was not opened", |
| 233 | + "property": "bankAccount", |
| 234 | + "input": { |
| 235 | + "operations": [ |
| 236 | + { |
| 237 | + "operation": "close" |
| 238 | + } |
| 239 | + ] |
| 240 | + }, |
| 241 | + "expected": { "error": "account not open" } |
| 242 | + }, |
| 243 | + { |
| 244 | + "uuid": "c06f534f-bdc2-4a02-a388-1063400684de", |
| 245 | + "description": "Cannot open an already opened account", |
| 246 | + "property": "bankAccount", |
| 247 | + "input": { |
| 248 | + "operations": [ |
| 249 | + { |
| 250 | + "operation": "open" |
| 251 | + }, |
| 252 | + { |
| 253 | + "operation": "open" |
| 254 | + } |
| 255 | + ] |
| 256 | + }, |
| 257 | + "expected": { "error": "account already open" } |
| 258 | + }, |
| 259 | + { |
| 260 | + "uuid": "0722d404-6116-4f92-ba3b-da7f88f1669c", |
| 261 | + "description": "Reopened account does not retain balance", |
| 262 | + "property": "bankAccount", |
| 263 | + "input": { |
| 264 | + "operations": [ |
| 265 | + { |
| 266 | + "operation": "open" |
| 267 | + }, |
| 268 | + { |
| 269 | + "operation": "deposit", |
| 270 | + "amount": 50 |
| 271 | + }, |
| 272 | + { |
| 273 | + "operation": "close" |
| 274 | + }, |
| 275 | + { |
| 276 | + "operation": "open" |
| 277 | + }, |
| 278 | + { |
| 279 | + "operation": "balance" |
| 280 | + } |
| 281 | + ] |
| 282 | + }, |
| 283 | + "expected": 0 |
| 284 | + }, |
| 285 | + { |
| 286 | + "uuid": "ec42245f-9361-4341-8231-a22e8d19c52f", |
| 287 | + "description": "Cannot withdraw more than deposited", |
| 288 | + "property": "bankAccount", |
| 289 | + "input": { |
| 290 | + "operations": [ |
| 291 | + { |
| 292 | + "operation": "open" |
| 293 | + }, |
| 294 | + { |
| 295 | + "operation": "deposit", |
| 296 | + "amount": 25 |
| 297 | + }, |
| 298 | + { |
| 299 | + "operation": "withdraw", |
| 300 | + "amount": 50 |
| 301 | + } |
| 302 | + ] |
| 303 | + }, |
| 304 | + "expected": { "error": "amount must be less than balance" } |
| 305 | + }, |
| 306 | + { |
| 307 | + "uuid": "4f381ef8-10ef-4507-8e1d-0631ecc8ee72", |
| 308 | + "description": "Cannot withdraw negative", |
| 309 | + "property": "bankAccount", |
| 310 | + "input": { |
| 311 | + "operations": [ |
| 312 | + { |
| 313 | + "operation": "open" |
| 314 | + }, |
| 315 | + { |
| 316 | + "operation": "deposit", |
| 317 | + "amount": 100 |
| 318 | + }, |
| 319 | + { |
| 320 | + "operation": "withdraw", |
| 321 | + "amount": -50 |
| 322 | + } |
| 323 | + ] |
| 324 | + }, |
| 325 | + "expected": { "error": "amount must be greater than 0" } |
| 326 | + }, |
| 327 | + { |
| 328 | + "uuid": "d45df9ea-1db0-47f3-b18c-d365db49d938", |
| 329 | + "description": "Cannot deposit negative", |
| 330 | + "property": "bankAccount", |
| 331 | + "input": { |
| 332 | + "operations": [ |
| 333 | + { |
| 334 | + "operation": "open" |
| 335 | + }, |
| 336 | + { |
| 337 | + "operation": "deposit", |
| 338 | + "amount": -50 |
| 339 | + } |
| 340 | + ] |
| 341 | + }, |
| 342 | + "expected": { "error": "amount must be greater than 0" } |
| 343 | + }, |
| 344 | + { |
| 345 | + "uuid": "ba0c1e0b-0f00-416f-8097-a7dfc97871ff", |
| 346 | + "description": "Can handle concurrent transactions", |
| 347 | + "comments": [ |
| 348 | + "This test is a good candidate to practice concurrency, which", |
| 349 | + "may not be available or possible in the implementing language track.", |
| 350 | + "Concurrency testing is often made by running the same operations in", |
| 351 | + "parallel, and then checking that the final state is as expected." |
| 352 | + ], |
| 353 | + "scenarios": ["concurrent"], |
| 354 | + "property": "bankAccount", |
| 355 | + "input": { |
| 356 | + "operations": [ |
| 357 | + { |
| 358 | + "operation": "open" |
| 359 | + }, |
| 360 | + { |
| 361 | + "operation": "concurrent", |
| 362 | + "number": 1000, |
| 363 | + "operations": [ |
| 364 | + { |
| 365 | + "operation": "deposit", |
| 366 | + "amount": 1 |
| 367 | + }, |
| 368 | + { |
| 369 | + "operation": "withdraw", |
| 370 | + "amount": 1 |
| 371 | + } |
| 372 | + ] |
| 373 | + }, |
| 374 | + { |
| 375 | + "operation": "balance" |
| 376 | + } |
| 377 | + ] |
| 378 | + }, |
| 379 | + "expected": 0 |
| 380 | + } |
| 381 | + ] |
| 382 | +} |
0 commit comments