Problem:
1. The principal is 1 million, the interest rate or the return on investment is 3%, and the investment period is 30, then the interest income obtained after 30 years is calculated by the formula of compounding interest: 1,000,000x (1+3%) ^30
2. If calculated according to simple interest, the final benefit of principal and interest
3. If a pension of $3 million is to be raised after 30, the average annual return is 3%, what is the amount of principal that must be invested now?
4. Interest rate is so low, compounding profits are so strong, if take 1 million yuan to buy annual rate of return 10% of the stock, if all smooth, too long, 1 million yuan becomes 2 million yuan?
5. If I want to turn $1 million into $2 million within 10 years, how much should I find the investment tool to help me achieve my goals? If you want to double the principal after 5 years, how much should the rate of return be at least?
6. If the savings of $30,000 are to be invested annually, with a return of 3% per annum, and then a new round of investment in these Benli and annuities, what will the total value of assets be after 30 years? What if we switch to 3000 a month? (calculation method of fixed investment income)
7. If a bank loan of 100,000 yuan, the annual interest rate of 6.5%, the term is 10, then the monthly equal and principal repayment amount? (For compounding conditions, the amount of the inferior amount
Write unit tests on US and compound interest calculation programs.
What are the scenarios?
Expected return value
Write the test program.
Run the test.
I have tested my own program manually and have the following scenarios:
Test module (Scene) |
Test input |
Expected results |
Run results |
Bug tracking |
Calculate compounding |
(principal, interest rate, duration) |
|
|
|
1 |
(10000, 0.03, 3) |
10927.27 |
That's right |
|
2 |
(0, 0.07, 5) |
Pop-up Tip: Please enter the correct principal (>0): |
0 |
Improved, prompt for re-entry of Principal |
3 |
(10000,-1, 5) |
Pop-up Tip: Please enter the >0 rate |
That's right |
|
4 |
(10000,0.05,-5) |
Pop-up Tip: Please enter the >0 year |
That's right |
Improved, prompting for re-entry of years |
|
|
|
|
|
Calculate Principal |
(Benli and, interest rate, term) |
|
|
|
1 |
(10000,0.03,3) |
Simple interest 9174.311, compounding 9151.41 |
That's right |
|
2 |
(0,0.05,5) |
Pop-up Tip: Please enter the amount of >0 |
Correct, prompt for input error |
|
3 |
(10000, 0, 5) |
Pop-up Tip: Please enter the >0d rate |
-inf |
Improved, prompt for interest rate input error |
4 |
(10000, 0.05,-5) |
Pop-up Tip: Please enter the >0 year |
Correct, prompt for input error |
|
|
|
|
|
|
Calculation life |
(Benli and, principal, interest rate) |
|
|
|
1 |
(10000,1000,0.05) |
47 |
That's right |
|
2 |
(0,1000,0.07) |
Pop-up tip: Please enter >0 Benli and |
Correct, prompt for input error |
|
3 |
(10000,0,0.05) |
Pop-up tip: Please enter >0 's principal |
That's right |
|
4 |
(10000,1000,0) |
Pop-up Tip: Please enter the >0 rate |
Correct, prompt for input error |
|
|
|
|
|
|
After my manual test, I found some illegal input bugs, and immediately stepped up to resolve the illegal input bug.
So, through this test, I learned how to detect my own programs and reduce the occurrence of bugs.
Compound Interest Calculation 4.0:https://github.com/lhr520czx/lee/blob/master/fljs4_0.c
Compound Interest Calculation 4.0 unit test