Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bank-account added #1418

Merged
merged 4 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 32 additions & 27 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"exemplar": [".meta/exemplar.ts"]
},
"exercises": {
"concept": [],
"practice": [
{
"slug": "hello-world",
Expand Down Expand Up @@ -587,7 +586,6 @@
"loops",
"exception_handling",
"lists",
"loops",
"transforming"
]
},
Expand Down Expand Up @@ -1006,7 +1004,6 @@
"strings"
]
},

{
"slug": "armstrong-numbers",
"name": "Armstrong Numbers",
Expand All @@ -1033,6 +1030,15 @@
"text_formatting"
]
},
{
"slug": "bank-account",
"name": "Bank Account",
"uuid": "3247f8b4-8b80-4c0b-bc3b-779f7a3eb291",
"practices": [],
"prerequisites": [],
"difficulty": 3,
"topics": ["classes", "conditionals"]
},
{
"slug": "rotational-cipher",
"name": "Rotational Cipher",
Expand Down Expand Up @@ -1066,8 +1072,8 @@
"practices": [],
"prerequisites": [],
"difficulty": 5,
"topics": ["algorithms", "callbacks", "conditionals", "lists"],
"status": "deprecated"
"status": "deprecated",
"topics": ["algorithms", "callbacks", "conditionals", "lists"]
},
{
"slug": "all-your-base",
Expand Down Expand Up @@ -1190,57 +1196,56 @@
}
]
},
"concepts": [],
"key_features": [
{
"icon": "evolving",
"title": "Evolving",
"content": "Typescript is a modern and constantly evolving open-source language supported by Microsoft."
"content": "Typescript is a modern and constantly evolving open-source language supported by Microsoft.",
"icon": "evolving"
},
{
"icon": "widely-used",
"title": "Widely used",
"content": "TypeScript is used by many libraries and frameworks, and integrates with JavaScript code as well."
"content": "TypeScript is used by many libraries and frameworks, and integrates with JavaScript code as well.",
"icon": "widely-used"
},
{
"icon": "dynamically-typed",
"title": "Typed JavaScript",
"content": "Typescript flexible typing system lets you describe what to expect, supporting gradual adoption."
"content": "Typescript flexible typing system lets you describe what to expect, supporting gradual adoption.",
"icon": "dynamically-typed"
},
{
"icon": "multi-paradigm",
"title": "Use any programming style",
"content": "Use prototype-based, object-oriented, functional, or declarative programming styles, and more."
"content": "Use prototype-based, object-oriented, functional, or declarative programming styles, and more.",
"icon": "multi-paradigm"
},
{
"icon": "tooling",
"title": "Consistently Good Tooling",
"content": "TS's JavaScript integration is handled by the language itself, enabling its tools and features."
"content": "TS's JavaScript integration is handled by the language itself, enabling its tools and features.",
"icon": "tooling"
},
{
"icon": "community",
"title": "Large Community",
"content": "The large number of users makes it easy to find answers, documentation, and libraries."
"content": "The large number of users makes it easy to find answers, documentation, and libraries.",
"icon": "community"
}
],
"tags": [
"execution_mode/compiled",
"paradigm/declarative",
"paradigm/functional",
"paradigm/imperative",
"paradigm/object_oriented",
"typing/static",
"typing/dynamic",
"typing/strong",
"typing/weak",
"execution_mode/compiled",
"platform/windows",
"platform/mac",
"platform/linux",
"platform/ios",
"platform/android",
"platform/ios",
"platform/linux",
"platform/mac",
"platform/web",
"platform/windows",
"runtime/language_specific",
"runtime/wasmtime",
"typing/dynamic",
"typing/static",
"typing/strong",
"typing/weak",
"used_for/artificial_intelligence",
"used_for/backends",
"used_for/cross_platform_development",
Expand Down
12 changes: 12 additions & 0 deletions exercises/practice/bank-account/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Instructions

Simulate a bank account supporting opening/closing, withdrawals, and deposits of money.
Watch out for concurrent transactions!

A bank account can be accessed in multiple ways.
Clients can make deposits and withdrawals using the internet, mobile phones, etc.
Shops can charge against the account.

Create an account that can be accessed from multiple threads/processes (terminology depends on your programming language).

It should be possible to close an account; operations against a closed account must fail.
13 changes: 13 additions & 0 deletions exercises/practice/bank-account/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
!.meta

# Protected or generated
.git
.vscode

# When using npm
node_modules/*

# Configuration files
.eslintrc.cjs
babel.config.cjs
jest.config.cjs
38 changes: 38 additions & 0 deletions exercises/practice/bank-account/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module.exports = {
root: true,
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
overrides: [
// Student provided files
{
files: ['*.ts'],
excludedFiles: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
extends: '@exercism/eslint-config-typescript',
},
// Exercism given tests
{
files: ['*.test.ts'],
excludedFiles: ['custom.test.ts'],
env: {
jest: true,
},
extends: '@exercism/eslint-config-typescript/maintainers',
},
// Student provided tests
{
files: ['custom.test.ts'],
env: {
jest: true,
},
extends: '@exercism/eslint-config-typescript',
},
// Exercism provided files
{
files: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
excludedFiles: ['custom.test.ts'],
extends: '@exercism/eslint-config-typescript/maintainers',
},
],
}
17 changes: 17 additions & 0 deletions exercises/practice/bank-account/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"authors": [
"therealowenrees"
],
"files": {
"solution": [
"bank-account.ts"
],
"test": [
"bank-account.test.ts"
],
"example": [
".meta/proof.ci.ts"
]
},
"blurb": "Simulate a bank account supporting opening/closing, withdraws, and deposits of money. Watch out for concurrent transactions!"
}
42 changes: 42 additions & 0 deletions exercises/practice/bank-account/.meta/proof.ci.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export class ValueError extends Error {
constructor() {
super('Bank account error')
}
}

export class BankAccount {
private _isOpen: boolean
private _balance: number

constructor() {
this._isOpen = false
this._balance = 0
}

open(): void {
if (this._isOpen) throw new ValueError()
this._isOpen = true
}

close(): void {
if (!this._isOpen) throw new ValueError()
this._isOpen = false
this._balance = 0
}

deposit(amount: number): void {
if (!this._isOpen || amount < 0) throw new ValueError()
this._balance += amount
}

withdraw(amount: number): void {
if (!this._isOpen || amount < 0 || amount > this._balance)
throw new ValueError()
this._balance -= amount
}

get balance(): number {
if (!this._isOpen) throw new ValueError()
return this._balance
}
}
42 changes: 42 additions & 0 deletions exercises/practice/bank-account/.meta/solutions/bank-account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export class ValueError extends Error {
constructor() {
super('Bank account error')
}
}

export class BankAccount {
private _isOpen: boolean
private _balance: number

constructor() {
this._isOpen = false
this._balance = 0
}

open(): void {
if (this._isOpen) throw new ValueError()
this._isOpen = true
}

close(): void {
if (!this._isOpen) throw new ValueError()
this._isOpen = false
this._balance = 0
}

deposit(amount: number): void {
if (!this._isOpen || amount < 0) throw new ValueError()
this._balance += amount
}

withdraw(amount: number): void {
if (!this._isOpen || amount < 0 || amount > this._balance)
throw new ValueError()
this._balance -= amount
}

get balance(): number {
if (!this._isOpen) throw new ValueError()
return this._balance
}
}
61 changes: 61 additions & 0 deletions exercises/practice/bank-account/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[983a1528-4ceb-45e5-8257-8ce01aceb5ed]
description = "Newly opened account has zero balance"

[e88d4ec3-c6bf-4752-8e59-5046c44e3ba7]
description = "Single deposit"

[3d9147d4-63f4-4844-8d2b-1fee2e9a2a0d]
description = "Multiple deposits"

[08f1af07-27ae-4b38-aa19-770bde558064]
description = "Withdraw once"

[6f6d242f-8c31-4ac6-8995-a90d42cad59f]
description = "Withdraw twice"

[45161c94-a094-4c77-9cec-998b70429bda]
description = "Can do multiple operations sequentially"

[f9facfaa-d824-486e-8381-48832c4bbffd]
description = "Cannot check balance of closed account"

[7a65ba52-e35c-4fd2-8159-bda2bde6e59c]
description = "Cannot deposit into closed account"

[a0a1835d-faae-4ad4-a6f3-1fcc2121380b]
description = "Cannot deposit into unopened account"

[570dfaa5-0532-4c1f-a7d3-0f65c3265608]
description = "Cannot withdraw from closed account"

[c396d233-1c49-4272-98dc-7f502dbb9470]
description = "Cannot close an account that was not opened"

[c06f534f-bdc2-4a02-a388-1063400684de]
description = "Cannot open an already opened account"

[0722d404-6116-4f92-ba3b-da7f88f1669c]
description = "Reopened account does not retain balance"

[ec42245f-9361-4341-8231-a22e8d19c52f]
description = "Cannot withdraw more than deposited"

[4f381ef8-10ef-4507-8e1d-0631ecc8ee72]
description = "Cannot withdraw negative"

[d45df9ea-1db0-47f3-b18c-d365db49d938]
description = "Cannot deposit negative"

[ba0c1e0b-0f00-416f-8097-a7dfc97871ff]
description = "Can handle concurrent transactions"
Loading
Loading