一.主要功能与需求分析
1.本金为100万,利率或者投资回报率为3%,投资年限为30年,那么,30年后所获得的利息收入:按复利计算公式来计算就是:1,000,000×(1+3%)^30
2.如果按照单利计算,本息的最终收益
3.假如30年之后要筹措到300万元的养老金,平均的年回报率是3%,那么,现在必须投入的本金是多少呢?
4.利率这么低,复利计算收益都这么厉害了,如果拿100万元去买年报酬率10%的股票,若一切顺利,过多长时间,100万元就变成200万元呢?
5.如果我希望在十年内将100万元变成200万元,应该找到报酬率在多少的投资工具来帮助我达成目标?如果想在5年后本金翻倍,报酬率就应至少为多少才行呢?
6.如果每年都将积蓄的3万元进行投资,每年都能获得3%的回报,然后将这些本利之和连同年金再投入新一轮的投资,那么,30年后资产总值将变为多少?如果换成每月定投3000呢?(定额定投收益计算办法)
7. 如果向银行贷款10万元,年利率6.5%,期限为10年,那么每月等额本息还款多少?(算复利条件下等额还款金额)
二.单元测试预期结果及其代码。
测试模块 |
测试输入 |
预期结果 |
运行结果 |
bug跟踪 |
复利计算 |
(本金,年限,利率,次数) |
终值 |
||
测试运算结果 |
(100.0,1,0.05,1) |
105.0 |
√ |
|
测试输出正数 |
(100.0,1,0.05,1) |
True |
√ |
|
测试输入负数 |
(-100.0,1,-0.05,1) | False | √ | 要添加输入控制 |
单利计算 |
(利率,本金,年限) |
终值 | ||
测试运算结果 | ("0.05","100.0","1") | 105.0 | √ | |
测试输入负数 | ("0.05","100.0","1") | True | √ | |
测试输出正数 | ("-0.05","-100.0","1") | False | √ | 要添加输入控制 |
投资年限 | (利率,本金,终值,次数) | |||
测试运算结果 | ("0.05","100.0","105.0","1") | 1 | √ | |
测试输出正数 | ("0.05","100.0","105.0","1") | True | √ | |
测试输入负数 | ("-0.05","-100.0","105.0","1") | false | √ | 要添加输入控制 |
...... | 以下结果与上表一致 |
package com.Junit.test; import static org.junit.Assert.*;
import interest.BestProject;
import interest.CompoundInterrest;
import interest.InterestTime;
import interest.PeriodicIncome;
import interest.Principal;
import interest.Refund;
import interest.SingleInterest; public class Test { @org.junit.Test
public void testCompoundInterrest() {
double f = new CompoundInterrest("0.05","100.0","1","1").Interrest();
assertEquals(105.0,f ,0.001);
assertTrue("输出为负数", f > 0);
double s = new CompoundInterrest("-0.05", "-100.0", "1", "1").Interrest();
assertFalse(s > 0);
}
@org.junit.Test
public void testSingleInterest() {
double f = new SingleInterest("0.05","100.0","1").Interest();
assertEquals(105.0, f, 0.001);
assertTrue("输出为负数", f > 0);
double s = new SingleInterest("-0.05","-100.0","1").Interest();
assertFalse(s > 0);
}
@org.junit.Test
public void testInterestTime() {
int t = new InterestTime("0.05","100.0","105.0","1").Interrest();
assertEquals(1, t);
assertTrue("输出为负数", t > 0);
double s = new InterestTime("-0.05","-100.0","105.0","1").Interrest();
assertFalse(s > 0);
}
@org.junit.Test
public void testPeriodicIncome() {
double f = new PeriodicIncome("0.01","100","1").Interrest();
assertEquals(101.0, f ,0.001);
assertTrue("输出为负数", f > 0);
double s = new PeriodicIncome("-0.01","-100","1").Interrest();
assertFalse(s > 0);
}
@org.junit.Test
public void testPrincipal () {
double f = new Principal("0.05","105.0","1","1").Interrest();
assertEquals(100.0, f, 0.001);
assertTrue("输出为负数", f > 0);
double s = new Principal("-0.05","-105.0","1","1").Interrest();
assertFalse(s > 0);
} @org.junit.Test
public void testBestProject () {
double f = new BestProject("200","100","1","1").Interrest();
assertEquals(1.0, f, 0.001);
assertTrue("输出为负数", f > 0);
double s = new BestProject("-200","100","1","1").Interrest();
assertFalse(s > 0);
}
@org.junit.Test
public void testRefund () {
double f = new Refund("0.87","1200","3").Interrest();
assertEquals(94.6147, f ,0.001);
assertTrue("输出为负数", f > 0);
double s = new Refund("-0.87","-1200","3").Interrest();
assertFalse(s > 0);
} }
三.运行情况
四.代码链接
https://github.com/liezh/Compound-Interest-5.0-Junit