exercism/ruby

[SavingAccounts]: Suggestion: change negative interest rate tests to return positive value

murichristopher opened this issue · 5 comments

Currenty we have four tests of negative interest rates:

  def test_minimal_negative_interest_rates
    assert_in_delta(-3.213, SavingsAccount.interest_rate(-0.000_1), 0.000_1)
  end
  
  def test_small_negative_interest_rates
    assert_in_delta(-3.213, SavingsAccount.interest_rate(-0.123), 0.000_1)
  end

  def test_regular_negative_interest_rates
    assert_in_delta(-3.213, SavingsAccount.interest_rate(-300.0), 0.000_1)
  end

  def test_large_negative_interest_rates
    assert_in_delta(-3.213, SavingsAccount.interest_rate(-55_555.444), 0.000_1)
  end

They require an interest rate on a negative balance to always be -3.213, no matter what its value, as long as it is less than 0

But a negative interest rate can cause bugs and possibly 'hamper' a student's learning, mainly because it's not very common to see banks and financial institutions using negative interest rates.

An interest rate of 3.123 (positive) applied to a negative balance should give the right result and avoid possible misunderstandings.

kotp commented

Should the test be focused on negative balance, rather than negative interest rate?

I would also note that it really does not matter what the interest rate for 0 balance might be, the result is always going to be 0. (Property of multiplying by 0.)

I agree about the idea though. The rate should be the rate, determined by the balance.

kotp commented

Also, the rate of 3,123 is very high, Ruby uses . for the decimal point, and so 3,123 is a syntax error (unless it is given in an argument block as two arguments of individual integers) and not equal to 3.123.

I think that the test should be focused on the negative balance because a negative interest rate does not seems very usual to me to deal with.

And yeah, you're right. I accidentally switched the dot to the comma, but I already fixed it

kotp commented

Would you like to make a PR with those ideas in mind?