One compound interest calculation of software engineering experiment--unit test

Source: Internet
Author: User

Unit Test for Compounding calculator

First, the requirements of the previous experimental topics

1. Customer said: Help me develop a compound interest calculation software.

2. If according to simple interest calculation, how much is the 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?

7. Do you write programs that allow customers to operate at will? What is the reaction of accidentally entering data and accidentally doing unconventional operating procedures?

8. 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, inferior amount repayment amount)

II. Results of software preparation

The specific software has been updated in previous experiments in the blog has been shown, do not repeat this list.

In this unit test blog, I mainly demonstrate two scenarios of unit testing, the rest of the test source code and the process does not repeat, I have put on GitHub, interested students can click the link to read: Https://github.com/skywalkersg/ruanjian /tree/master/fuligainew

Scenario One: The customer said: "I have a principal of 10,000 yuan, the interest rate is 2%, 3 years, the number of compounding is 2, finally can get how much compound interest final value?"

In the compounding calculator I made, I got the following data:

the results are due to 10615 of the compounding end value.

1. After the first unit test results are:

2. Due to the failure of the test, I tried to make a separate output before the data entry and comparison process, so as to determine where the error occurred.

3. It can be seen that the error in the data caused the unit test error, after the revision of the final test data as follows and the end value of compound interest is 10615.201506009998 yuan:

Scenario Two: Interest rate is so low, compound interest is so strong profits, if you take 1 million yuan to buy the annual return rate of 10% of the stock, if all goes well, too long, 1 million yuan becomes 2 million yuan?

In the compounding calculator, the original data is as follows:

The results are due for 8 years.

1. The first unit test results are as follows:

2. Use the same method to detect errors in the correction:

3. The results of the final result and the expected results are calculated as 8 years:

The original code for the three or two unit tests is as follows:

1  Public classTesthanshu {2 //The principal is 10,000 yuan, the interest rate is 2%, the deposit 3 years, the compounding number is 2, finally can obtain how many compound interest finally value? 3 @Test4      Public voidTestSuanFa01 () {5Hanshu HS =NewHanshu ("10000", "0.02", "3", "2",NULL);6         DoubleFuture=HS. SuanFa01 ();7 System.out.println (future);8         BooleanFlag = 10615.201506009998==Future ;9 System.out.println (flag);TenAssertequals (true, flag); One          A     } -  - } the  -  -  Public classTesttime { - //interest rate is so low, compounding income is so strong, if take 1 million yuan to buy annual return rate of 10% of the stock, if all smooth, too long, 1 million yuan becomes 2 million yuan?  + @Test -      Public voidTesttime () { +Hanshu HS =NewHanshu ("1000000", "0.1",NULL, "1", "2000000"); A         intYear= (int) HS. Time (); at //System.out.println (year); -         BooleanFlag = 8==Year ; -Assertequals (true, flag); -     } -  -}

The rest of the tests are broadly similar and are not listed.

Iv. Summary of the experiment

The unit Test experiment is the first attempt to write their own code to test, the main error of the experiment is mainly in the data errors, the program itself is not a problem, so stealing thought this experiment is still successful, but should be not very understanding of the function of unit testing and more testing methods and content, So I think the content of this test is relatively simple, I hope in the future learning I can become more proficient in the use of unit testing, the use of it in more powerful, complex test, master the core of this software engineering.

One compound interest calculation of software engineering experiment--unit test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.