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

fix: test case for interest_is_interesting_test.cpp #928

Closed
wants to merge 1 commit into from

Conversation

mhdadk
Copy link

@mhdadk mhdadk commented Dec 4, 2024

The following test case contains an incorrect want value.

TEST_CASE("Years before large difference between start and target balance", "[task_4]") {
double balance{2345.67};
double target_balance{12345.6789};
int want{85};
REQUIRE(years_until_desired_balance(balance, target_balance) == want);
}

Currently, the test case has the following parameters:

  • $\texttt{balance} = 2345.67$
  • $\texttt{target\_balance} = 12345.6789$
  • $\texttt{want} = 85$

However, the value of want is incorrect. Since $\texttt{balance} = 2345.67$, then, as given in the instructions, the interest rate is $\% 1.621$. If we assume that $\texttt{want} = 85$ as given above, then the final balance after $\texttt{want}$ years is

$$\begin{align} \texttt{balance} \times \left(1 + \frac{\verb|interest_rate|}{100}\right)^\texttt{want} &= 2345.67 \times \left(1 + \frac{1.621}{100}\right)^{85} \\\ &\approx \$ 9201.558 \end{align}$$

Similarly, the final balance after $\texttt{want} - 1$ years is approximately $\$ 9054.78$. If the want value was correct, then the target balance would have been between the final balance after want - 1 years and the final balance after want years. However, this is not the case.

This PR fixes the want value by setting it to $104$ years. We can see that this is indeed correct since

$$\begin{align} 2345.67 \times \left(1 + \frac{1.621}{100}\right)^{103} &\approx \$ 12,290.334 \\\ &< \verb|target_balance| = 12345.6789 \\\ &< 2345.67 \times \left(1 + \frac{1.621}{100}\right)^{104} \approx \$ 12,489.561 \end{align}$$

The test case titled "Years before large difference between start and target balance" contains an incorrect `want`.

Currently, `want == 85`, but if we substitute this into the expressions `balance * (1 + (interest_rate / 100))^want` and `balance * (1 + (interest_rate / 100))^(want + 1)`, we see that both expressions have a value that is much lower than `target_balance`.

This commit fixes this by setting `want` to the correct value.
Copy link
Contributor

github-actions bot commented Dec 4, 2024

This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested.

If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos.

[no important files changed]

For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping @exercism/maintainers-admin in a comment. Thank you!

Copy link
Contributor

github-actions bot commented Dec 4, 2024

Hello. Thanks for opening a PR on Exercism 🙂

We ask that all changes to Exercism are discussed on our Community Forum before being opened on GitHub. To enforce this, we automatically close all PRs that are submitted. That doesn't mean your PR is rejected but that we want the initial discussion about it to happen on our forum where a wide range of key contributors across the Exercism ecosystem can weigh in.

You can use this link to copy this into a new topic on the forum. If we decide the PR is appropriate, we'll reopen it and continue with it, so please don't delete your local branch.

If you're interested in learning more about this auto-responder, please read this blog post.


Note: If this PR has been pre-approved, please link back to this PR on the forum thread and a maintainer or staff member will reopen it.

@github-actions github-actions bot closed this Dec 4, 2024
@vaeng vaeng reopened this Dec 4, 2024
@mhdadk
Copy link
Author

mhdadk commented Dec 4, 2024

FYI: I posted the relevant forum discussion here.

@mhdadk mhdadk closed this by deleting the head repository Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants