From 2e38217bd500bdb950fda3197bea1ced78b67695 Mon Sep 17 00:00:00 2001 From: Meatball Date: Thu, 13 Jun 2024 08:22:47 +0200 Subject: [PATCH 1/5] Implement bank account --- .ruby-version | 2 +- config.json | 244 ++++++------------ .../bank-account/.docs/instructions.md | 10 + .../bank-account/.docs/introduction.md | 20 ++ .../practice/bank-account/.meta/config.json | 15 ++ .../practice/bank-account/.meta/example.rb | 48 ++++ .../practice/bank-account/.meta/tests.toml | 62 +++++ .../practice/bank-account/bank_account.rb | 7 + .../bank-account/bank_account_test.rb | 151 +++++++++++ 9 files changed, 391 insertions(+), 168 deletions(-) create mode 100644 exercises/practice/bank-account/.docs/instructions.md create mode 100644 exercises/practice/bank-account/.docs/introduction.md create mode 100644 exercises/practice/bank-account/.meta/config.json create mode 100644 exercises/practice/bank-account/.meta/example.rb create mode 100644 exercises/practice/bank-account/.meta/tests.toml create mode 100644 exercises/practice/bank-account/bank_account.rb create mode 100644 exercises/practice/bank-account/bank_account_test.rb diff --git a/.ruby-version b/.ruby-version index be94e6f53d..619b537668 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.2.2 +3.3.3 diff --git a/config.json b/config.json index 099d865cca..cc40e0991a 100644 --- a/config.json +++ b/config.json @@ -41,9 +41,7 @@ "concepts": [ "basics" ], - "prerequisites": [ - - ] + "prerequisites": [] }, { "slug": "amusement-park", @@ -128,7 +126,7 @@ "prerequisites": [ "symbols" ] - }, + }, { "slug": "bird-count", "name": "Bird Count", @@ -207,12 +205,8 @@ "slug": "hello-world", "name": "Hello World", "uuid": "4fe19484-4414-471b-a106-73c776c61388", - "practices": [ - - ], - "prerequisites": [ - - ], + "practices": [], + "prerequisites": [], "difficulty": 1 }, { @@ -306,9 +300,7 @@ "slug": "word-count", "name": "Word Count", "uuid": "e9d29769-8d4d-4159-8d6f-762db5339707", - "practices": [ - - ], + "practices": [], "prerequisites": [ "strings", "numbers" @@ -365,9 +357,7 @@ "slug": "scrabble-score", "name": "Scrabble Score", "uuid": "d934ebce-9ac3-4a41-bcb8-d70480170438", - "practices": [ - - ], + "practices": [], "prerequisites": [ "numbers", "strings" @@ -430,9 +420,7 @@ "slug": "gigasecond", "name": "Gigasecond", "uuid": "0fb594a1-193b-4ccf-8de2-eb6a81708b29", - "practices": [ - - ], + "practices": [], "prerequisites": [ "numbers" ], @@ -577,9 +565,7 @@ "slug": "armstrong-numbers", "name": "Armstrong Numbers", "uuid": "77c5c7e6-265a-4f1a-9bc4-851f8f825420", - "practices": [ - - ], + "practices": [], "prerequisites": [ "numbers", "booleans" @@ -602,9 +588,7 @@ "slug": "phone-number", "name": "Phone Number", "uuid": "b68665d5-14ef-4351-ac4a-c28a80c27b3d", - "practices": [ - - ], + "practices": [], "prerequisites": [ "strings" ], @@ -614,9 +598,7 @@ "slug": "grains", "name": "Grains", "uuid": "22519f53-4516-43bc-915e-07d58e48f617", - "practices": [ - - ], + "practices": [], "prerequisites": [ "conditionals", "loops", @@ -684,9 +666,7 @@ "slug": "pythagorean-triplet", "name": "Pythagorean Triplet", "uuid": "43aad536-0e24-464c-9554-cbc2699d0543", - "practices": [ - - ], + "practices": [], "prerequisites": [ "numbers" ], @@ -753,14 +733,10 @@ "slug": "accumulate", "name": "Accumulate", "uuid": "2c71fc3a-2c93-402b-b091-697b795ce3ba", - "status": "deprecated", - "practices": [ - - ], - "prerequisites": [ - - ], - "difficulty": 1 + "practices": [], + "prerequisites": [], + "difficulty": 1, + "status": "deprecated" }, { "slug": "bob", @@ -779,22 +755,16 @@ "slug": "strain", "name": "Strain", "uuid": "ac0966a9-822b-45be-91d9-36f6706ea76f", - "status": "deprecated", - "practices": [ - - ], - "prerequisites": [ - - ], - "difficulty": 2 + "practices": [], + "prerequisites": [], + "difficulty": 2, + "status": "deprecated" }, { "slug": "nth-prime", "name": "Nth Prime", "uuid": "16baef71-6234-4928-a2d4-a19eb8e110b8", - "practices": [ - - ], + "practices": [], "prerequisites": [ "numbers", "exceptions" @@ -818,9 +788,7 @@ "slug": "alphametics", "name": "Alphametics", "uuid": "2323a2a5-c181-4c1e-9c5f-f6b92b2de511", - "practices": [ - - ], + "practices": [], "prerequisites": [ "strings" ], @@ -857,9 +825,7 @@ "slug": "matching-brackets", "name": "Matching Brackets", "uuid": "26f6e297-7980-4472-8ce7-157b62b0ff40", - "practices": [ - - ], + "practices": [], "prerequisites": [ "strings", "booleans" @@ -899,9 +865,7 @@ "slug": "allergies", "name": "Allergies", "uuid": "7a67a62f-9331-4776-a5b5-aaba7ad1e1e6", - "practices": [ - - ], + "practices": [], "prerequisites": [ "arrays", "booleans" @@ -912,9 +876,7 @@ "slug": "rail-fence-cipher", "name": "Rail Fence Cipher", "uuid": "64196fe5-2270-4113-a614-fbfbb6d00f2b", - "practices": [ - - ], + "practices": [], "prerequisites": [ "numbers", "strings" @@ -1014,9 +976,7 @@ "slug": "secret-handshake", "name": "Secret Handshake", "uuid": "c1ebad1b-d5aa-465a-b5ef-9e717ab5db9e", - "practices": [ - - ], + "practices": [], "prerequisites": [ "strings", "arrays" @@ -1040,9 +1000,7 @@ "slug": "crypto-square", "name": "Crypto Square", "uuid": "86f8e33d-31b7-43e3-8ea3-2e391133704a", - "practices": [ - - ], + "practices": [], "prerequisites": [ "strings" ], @@ -1064,9 +1022,7 @@ "slug": "robot-name", "name": "Robot Name", "uuid": "76a0fd0a-cc65-4be3-acc8-7348bb67ad5a", - "practices": [ - - ], + "practices": [], "prerequisites": [ "strings" ], @@ -1091,9 +1047,7 @@ "slug": "dominoes", "name": "Dominoes", "uuid": "705f3eb6-55a9-476c-b3f2-e9f3cb0bbe37", - "practices": [ - - ], + "practices": [], "prerequisites": [ "numbers", "booleans" @@ -1104,9 +1058,7 @@ "slug": "pig-latin", "name": "Pig Latin", "uuid": "efc0e498-891a-4e91-a6aa-fae635573a83", - "practices": [ - - ], + "practices": [], "prerequisites": [ "strings" ], @@ -1171,9 +1123,7 @@ "slug": "grade-school", "name": "Grade School", "uuid": "4460742c-2beb-48d7-94e6-72ff13c68c71", - "practices": [ - - ], + "practices": [], "prerequisites": [ "strings", "numbers" @@ -1226,9 +1176,7 @@ "slug": "kindergarten-garden", "name": "Kindergarten Garden", "uuid": "04bde625-e363-4d8b-880f-db7bf86286eb", - "practices": [ - - ], + "practices": [], "prerequisites": [ "strings" ], @@ -1238,9 +1186,7 @@ "slug": "largest-series-product", "name": "Largest Series Product", "uuid": "7cb55328-1b11-4544-94c0-945444d9a6a4", - "practices": [ - - ], + "practices": [], "prerequisites": [ "strings", "loops", @@ -1265,9 +1211,7 @@ "slug": "custom-set", "name": "Custom Set", "uuid": "4f74b3cd-f995-4b8c-9b57-23f073261d0e", - "practices": [ - - ], + "practices": [], "prerequisites": [ "arrays", "numbers", @@ -1292,9 +1236,7 @@ "slug": "linked-list", "name": "Linked List", "uuid": "92c9aafc-791d-4aaf-a136-9bee14f6ff95", - "practices": [ - - ], + "practices": [], "prerequisites": [ "numbers" ], @@ -1304,9 +1246,7 @@ "slug": "poker", "name": "Poker", "uuid": "9a59ba44-34f5-410b-a1e6-9a5c47c52d9e", - "practices": [ - - ], + "practices": [], "prerequisites": [ "strings", "conditionals" @@ -1330,9 +1270,7 @@ "slug": "complex-numbers", "name": "Complex Numbers", "uuid": "d75bd7c0-52c5-44f2-a046-f63cb332425f", - "practices": [ - - ], + "practices": [], "prerequisites": [ "numbers" ], @@ -1342,12 +1280,8 @@ "slug": "meetup", "name": "Meetup", "uuid": "8120e133-9561-4f82-8081-10c19f7f6ba3", - "practices": [ - - ], - "prerequisites": [ - - ], + "practices": [], + "prerequisites": [], "difficulty": 3 }, { @@ -1410,9 +1344,7 @@ "slug": "zipper", "name": "Zipper", "uuid": "239b8e79-2983-4ce0-9dda-9bb999e79d11", - "practices": [ - - ], + "practices": [], "prerequisites": [ "numbers" ], @@ -1451,9 +1383,7 @@ "slug": "pascals-triangle", "name": "Pascal's Triangle", "uuid": "4ff8b056-f27d-4bdf-b7af-214448db4260", - "practices": [ - - ], + "practices": [], "prerequisites": [ "loops", "numbers" @@ -1464,9 +1394,7 @@ "slug": "queen-attack", "name": "Queen Attack", "uuid": "2ce9b158-e730-4c86-8639-bd08af9f80f4", - "practices": [ - - ], + "practices": [], "prerequisites": [ "booleans", "conditionals", @@ -1494,9 +1422,7 @@ "slug": "connect", "name": "Connect", "uuid": "538a6768-bae5-437c-9cdf-765d73a79643", - "practices": [ - - ], + "practices": [], "prerequisites": [ "strings", "arrays", @@ -1508,12 +1434,8 @@ "slug": "binary", "name": "Binary", "uuid": "43bc27ed-d2fa-4173-8665-4459b71c9a3a", - "practices": [ - - ], - "prerequisites": [ - - ], + "practices": [], + "prerequisites": [], "difficulty": 1, "status": "deprecated" }, @@ -1521,12 +1443,8 @@ "slug": "hexadecimal", "name": "Hexadecimal", "uuid": "6984cc14-91f8-47a7-b7e2-4b210a5dbc5c", - "practices": [ - - ], - "prerequisites": [ - - ], + "practices": [], + "prerequisites": [], "difficulty": 1, "status": "deprecated" }, @@ -1534,12 +1452,8 @@ "slug": "octal", "name": "Octal", "uuid": "cae4e000-3aac-41f7-b727-f9cce12d058d", - "practices": [ - - ], - "prerequisites": [ - - ], + "practices": [], + "prerequisites": [], "difficulty": 1, "status": "deprecated" }, @@ -1547,12 +1461,8 @@ "slug": "point-mutations", "name": "Point Mutations", "uuid": "89bd3d71-000f-4cd9-9a84-ad1b22ddbd33", - "practices": [ - - ], - "prerequisites": [ - - ], + "practices": [], + "prerequisites": [], "difficulty": 1, "status": "deprecated" }, @@ -1560,12 +1470,8 @@ "slug": "trinary", "name": "Trinary", "uuid": "f6735416-4be6-4eb8-b6b9-cb61671ce25e", - "practices": [ - - ], - "prerequisites": [ - - ], + "practices": [], + "prerequisites": [], "difficulty": 1, "status": "deprecated" }, @@ -1573,12 +1479,8 @@ "slug": "microwave", "name": "Microwave", "uuid": "34e715a6-4d22-4b74-a26a-409283ac419c", - "practices": [ - - ], - "prerequisites": [ - - ], + "practices": [], + "prerequisites": [], "difficulty": 2 }, { @@ -1594,6 +1496,14 @@ "conditionals" ], "difficulty": 3 + }, + { + "slug": "bank-account", + "name": "Bank Account", + "uuid": "48b91d4d-2fd4-4941-8f3f-030872daec88", + "practices": [], + "prerequisites": [], + "difficulty": 1 } ] }, @@ -1672,7 +1582,7 @@ "uuid": "ec83aa13-0861-46d4-a126-2ebf6b8705d3", "slug": "ranges", "name": "Ranges" - }, + }, { "uuid": "0189a402-ed46-47ee-9f5b-cfa5f557720d", "slug": "enumeration", @@ -1701,44 +1611,44 @@ ], "key_features": [ { - "icon": "fun", "title": "Developer happiness", - "content": "Ruby puts developer-happiness first. It has an elegant syntax that is natural to read and write." + "content": "Ruby puts developer-happiness first. It has an elegant syntax that is natural to read and write.", + "icon": "fun" }, { - "icon": "extensible", "title": "Metaprogramming magic", - "content": "Ruby code can write and invoke Ruby code." + "content": "Ruby code can write and invoke Ruby code.", + "icon": "extensible" }, { - "icon": "garbage-collected", "title": "Garbage Collection", - "content": "Garbage collection done via mark and sweep, stays out of your way." + "content": "Garbage collection done via mark and sweep, stays out of your way.", + "icon": "garbage-collected" }, { - "icon": "powerful", "title": "Large standard library", - "content": "Ruby's standard library provides a wealth of classes utilities for common tasks." + "content": "Ruby's standard library provides a wealth of classes utilities for common tasks.", + "icon": "powerful" }, { - "icon": "tooling", "title": "Flexible package manager", - "content": "Packages (gems) can be centrally managed, but can also include custom or private gem stores." + "content": "Packages (gems) can be centrally managed, but can also include custom or private gem stores.", + "icon": "tooling" }, { - "icon": "dynamically-typed", "title": "Strong, dynamic typing", - "content": "Ruby is strong and dynamically typed and supports 'Duck Typing'. Everything in Ruby is an object" + "content": "Ruby is strong and dynamically typed and supports 'Duck Typing'. Everything in Ruby is an object", + "icon": "dynamically-typed" } ], "tags": [ + "execution_mode/interpreted", "paradigm/functional", "paradigm/object_oriented", "platform/linux", - "platform/windows", "platform/mac", + "platform/windows", "runtime/language_specific", - "execution_mode/interpreted", "typing/dynamic", "typing/strong", "used_for/backends", diff --git a/exercises/practice/bank-account/.docs/instructions.md b/exercises/practice/bank-account/.docs/instructions.md new file mode 100644 index 0000000000..0955520bbf --- /dev/null +++ b/exercises/practice/bank-account/.docs/instructions.md @@ -0,0 +1,10 @@ +# Instructions + +Your task is to implement bank accounts supporting opening/closing, withdrawals, and deposits of money. + +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. +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. + +It should be possible to close an account; operations against a closed account must fail. + +[wikipedia]: https://en.wikipedia.org/wiki/Race_condition#In_software diff --git a/exercises/practice/bank-account/.docs/introduction.md b/exercises/practice/bank-account/.docs/introduction.md new file mode 100644 index 0000000000..650b5d9c46 --- /dev/null +++ b/exercises/practice/bank-account/.docs/introduction.md @@ -0,0 +1,20 @@ +# Introduction + +After years of filling out forms and waiting, you've finally acquired your banking license. +This means you are now officially eligible to open your own bank, hurray! + +Your first priority is to get the IT systems up and running. +After a day of hard work, you can already open and close accounts, as well as handle withdrawals and deposits. + +Since you couldn't be bothered writing tests, you invite some friends to help test the system. +However, after just five minutes, one of your friends claims they've lost money! +While you're confident your code is bug-free, you start looking through the logs to investigate. + +Ah yes, just as you suspected, your friend is at fault! +They shared their test credentials with another friend, and together they conspired to make deposits and withdrawals from the same account _in parallel_. +Who would do such a thing? + +While you argue that it's physically _impossible_ for someone to access their account in parallel, your friend smugly notifies you that the banking rules _require_ you to support this. +Thus, no parallel banking support, no go-live signal. +Sighing, you create a mental note to work on this tomorrow. +This will set your launch date back at _least_ one more day, but well... diff --git a/exercises/practice/bank-account/.meta/config.json b/exercises/practice/bank-account/.meta/config.json new file mode 100644 index 0000000000..857174088e --- /dev/null +++ b/exercises/practice/bank-account/.meta/config.json @@ -0,0 +1,15 @@ +{ + "authors": ["meatball133"], + "files": { + "solution": [ + "bank_account.rb" + ], + "test": [ + "bank_account_test.rb" + ], + "example": [ + ".meta/example.rb" + ] + }, + "blurb": "Simulate a bank account supporting opening/closing, withdraws, and deposits of money. Watch out for concurrent transactions!" +} diff --git a/exercises/practice/bank-account/.meta/example.rb b/exercises/practice/bank-account/.meta/example.rb new file mode 100644 index 0000000000..c7929af85e --- /dev/null +++ b/exercises/practice/bank-account/.meta/example.rb @@ -0,0 +1,48 @@ +class BankAccount + def initialize + @balance = 0 + @status = false + end + + def balance + unless @status + raise ArgumentError.new("You can't check the balance of a closed account") + end + @balance + end + + def open + if @status + raise ArgumentError.new("You can't open an already open account") + end + @status = true + end + + def close + unless @status + raise ArgumentError.new("You can't close an already closed account") + end + @balance = 0 + @status = false + end + + def deposit(amount) + if amount < 0 + raise ArgumentError.new("You can't deposit a negative amount") + elsif !@status + raise ArgumentError.new("You can't deposit money into a closed account") + end + @balance += amount + end + + def withdraw(amount) + if amount < 0 + raise ArgumentError.new("You can't withdraw a negative amount") + elsif amount > @balance + raise ArgumentError.new("You can't withdraw more than you have") + elsif !@status + raise ArgumentError.new("You can't withdraw money into a closed account") + end + @balance -= amount + end +end diff --git a/exercises/practice/bank-account/.meta/tests.toml b/exercises/practice/bank-account/.meta/tests.toml new file mode 100644 index 0000000000..655ea7ae5a --- /dev/null +++ b/exercises/practice/bank-account/.meta/tests.toml @@ -0,0 +1,62 @@ +# 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" +include = false \ No newline at end of file diff --git a/exercises/practice/bank-account/bank_account.rb b/exercises/practice/bank-account/bank_account.rb new file mode 100644 index 0000000000..85c4555869 --- /dev/null +++ b/exercises/practice/bank-account/bank_account.rb @@ -0,0 +1,7 @@ +=begin +Write your code for the 'Bank Account' exercise in this file. Make the tests in +`bank_account_test.rb` pass. + +To get started with TDD, see the `README.md` file in your +`ruby/bank-account` directory. +=end diff --git a/exercises/practice/bank-account/bank_account_test.rb b/exercises/practice/bank-account/bank_account_test.rb new file mode 100644 index 0000000000..50a6336206 --- /dev/null +++ b/exercises/practice/bank-account/bank_account_test.rb @@ -0,0 +1,151 @@ +require 'minitest/autorun' +require_relative 'bank_account' + +class BankAccountTest < Minitest::Test + def test_newly_opened_account_has_zero_balance + # skip + bank_account = BankAccount.new + bank_account.open + assert_equal bank_account.balance, 0 + end + + def test_single_deposit + skip + bank_account = BankAccount.new + bank_account.open + bank_account.deposit(100) + assert_equal bank_account.balance, 100 + end + + def test_multiple_deposits + skip + bank_account = BankAccount.new + bank_account.open + bank_account.deposit(100) + bank_account.deposit(50) + assert_equal bank_account.balance, 150 + end + + def test_withdraw_once + skip + bank_account = BankAccount.new + bank_account.open + bank_account.deposit(100) + bank_account.withdraw(75) + assert_equal bank_account.balance, 25 + end + + def test_withdraw_twice + skip + bank_account = BankAccount.new + bank_account.open + bank_account.deposit(100) + bank_account.withdraw(80) + bank_account.withdraw(20) + assert_equal bank_account.balance, 0 + end + + def test_can_do_multiple_operations_sequentially + skip + bank_account = BankAccount.new + bank_account.open + bank_account.deposit(100) + bank_account.deposit(110) + bank_account.withdraw(200) + bank_account.deposit(60) + bank_account.withdraw(50) + assert_equal bank_account.balance, 20 + end + + def test_cannot_check_balance_of_closed_account + skip + bank_account = BankAccount.new + bank_account.open + bank_account.close + assert_raises(ArgumentError, "You can't check the balance of a closed account") { bank_account.balance } + end + + def test_cannot_check_balance_of_closed_account + skip + bank_account = BankAccount.new + bank_account.open + bank_account.close + assert_raises(ArgumentError, "You can't check the balance of a closed account") { bank_account.balance } + end + + def test_cannot_check_balance_of_closed_account + skip + bank_account = BankAccount.new + bank_account.open + bank_account.close + assert_raises(ArgumentError, "You can't check the balance of a closed account") { bank_account.balance } + end + + def test_cannot_deposit_into_closed_account + skip + bank_account = BankAccount.new + bank_account.open + bank_account.close + assert_raises(ArgumentError, "You can't deposit money into a closed account") { bank_account.deposit(50) } + end + + def test_cannot_deposit_into_unopened_account + skip + bank_account = BankAccount.new + assert_raises(ArgumentError, "You can't deposit money into a closed account") { bank_account.deposit(50) } + end + + def test_cannot_withdraw_from_closed_account + skip + bank_account = BankAccount.new + bank_account.open + bank_account.close + assert_raises(ArgumentError, "You can't withdraw money into a closed account") { bank_account.withdraw(50) } + end + + def test_cannot_close_an_account_that_was_not_opened + skip + bank_account = BankAccount.new + assert_raises(ArgumentError, "You can't close an already closed account") { bank_account.close } + end + + def test_cannot_open_an_already_opened_account + skip + bank_account = BankAccount.new + bank_account.open + assert_raises(ArgumentError, "You can't open an already open account") { bank_account.open } + end + + def test_reopened_account_does_not_retain_balance + skip + bank_account = BankAccount.new + bank_account.open + bank_account.deposit(50) + bank_account.close + bank_account.open + assert_equal bank_account.balance, 0 + end + + def test_cannot_withdraw_more_than_deposited + skip + bank_account = BankAccount.new + bank_account.open + bank_account.deposit(25) + assert_raises(ArgumentError, "You can't withdraw more than you have") { bank_account.withdraw(50) } + end + + def test_cannot_withdraw_negative + skip + bank_account = BankAccount.new + bank_account.open + bank_account.deposit(100) + assert_raises(ArgumentError, "You can't withdraw a negative amount") { bank_account.withdraw(-50) } + end + + def test_cannot_deposit_negative + skip + bank_account = BankAccount.new + bank_account.open + assert_raises(ArgumentError, "You can't deposit a negative amount") { bank_account.deposit(-50) } + end +end From e0a15955cfd2d6acd74b043c74196c425eec4d90 Mon Sep 17 00:00:00 2001 From: Meatball Date: Thu, 13 Jun 2024 08:23:24 +0200 Subject: [PATCH 2/5] Remove ruby version change --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index 619b537668..be94e6f53d 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.3.3 +3.2.2 From 6c4f716ed853fede13b3a02985170a4710232633 Mon Sep 17 00:00:00 2001 From: Meatball Date: Fri, 14 Jun 2024 14:06:22 +0200 Subject: [PATCH 3/5] Fix config.json file --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index 8992c93421..58e84b1a4d 100644 --- a/config.json +++ b/config.json @@ -1561,7 +1561,7 @@ "uuid": "48b91d4d-2fd4-4941-8f3f-030872daec88", "practices": [], "prerequisites": [], - "difficulty": 1 + "difficulty": 1, "slug": "gilded-rose", "name": "Gilded Rose", "uuid": "19f65173-5c79-4a6a-b9e1-352ec438a3c4", From e4342c6b68c590cfba33157e3da4a0de945c5f39 Mon Sep 17 00:00:00 2001 From: Meatball Date: Fri, 14 Jun 2024 14:07:51 +0200 Subject: [PATCH 4/5] Actually fix config --- config.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config.json b/config.json index 58e84b1a4d..5f1e918db3 100644 --- a/config.json +++ b/config.json @@ -1561,7 +1561,9 @@ "uuid": "48b91d4d-2fd4-4941-8f3f-030872daec88", "practices": [], "prerequisites": [], - "difficulty": 1, + "difficulty": 3 + }, + { "slug": "gilded-rose", "name": "Gilded Rose", "uuid": "19f65173-5c79-4a6a-b9e1-352ec438a3c4", From c6e8ea0d63282ddea520a90b206b9df8512fe607 Mon Sep 17 00:00:00 2001 From: Meatball Date: Fri, 14 Jun 2024 14:10:32 +0200 Subject: [PATCH 5/5] Remove duplicate test --- .../practice/bank-account/bank_account_test.rb | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/exercises/practice/bank-account/bank_account_test.rb b/exercises/practice/bank-account/bank_account_test.rb index 50a6336206..6eff9d4350 100644 --- a/exercises/practice/bank-account/bank_account_test.rb +++ b/exercises/practice/bank-account/bank_account_test.rb @@ -65,22 +65,6 @@ def test_cannot_check_balance_of_closed_account assert_raises(ArgumentError, "You can't check the balance of a closed account") { bank_account.balance } end - def test_cannot_check_balance_of_closed_account - skip - bank_account = BankAccount.new - bank_account.open - bank_account.close - assert_raises(ArgumentError, "You can't check the balance of a closed account") { bank_account.balance } - end - - def test_cannot_check_balance_of_closed_account - skip - bank_account = BankAccount.new - bank_account.open - bank_account.close - assert_raises(ArgumentError, "You can't check the balance of a closed account") { bank_account.balance } - end - def test_cannot_deposit_into_closed_account skip bank_account = BankAccount.new