Compound Interest Calculator4.0
Compound Interest Calculator4.0
1.团队协作准备:每个同学在github上完成FORK,COMMENT(学号后三位+姓名),PR,MERGE的过程。

2.你的RP由你的程序质量决定。
对我们和复利计算程序,写单元测试。
| 测试模块 | 测试输入 | 预期结果 | 运行结果 | bug跟踪 |
| 计算终值 | (本金,年限,利率,次数) | 终值 | ||
| 1 | (1000000,30,0.03,30) | 2427262 | 2427262.4711896623 | |
| 2 | (3000000,30,0.03,30) | 1235960 | 1235960.2785477191 | |
| 3 | (1000000,3000000,0.03) | 37 | 37 | |
| 4 | (1000000,3000000,30) | 0.1 | 0.1 |
import org.junit.Test;
import org.junit.Assert;
import junit.framework.TestCase; public class CalculatorTest extends TestCase {
//所有的终值误差在1.0以内算是正确的
@Test
public void testFuli(){
Calculator4 k=new Calculator4();
double money=1000000;
double rate=0.03;
int years=30;
double sum;
sum=money*(Math.pow(1+rate, years));
System.out.println("sum="+sum);
Assert.assertEquals(2427262, sum,1.0);
} @Test
public void testPrincipal(){
Calculator4 k=new Calculator4();
double sum=3000000;
int years=30;
double rate=0.03;
double money;
money=sum/(Math.pow(1+rate, years));
System.out.println("money="+money);
Assert.assertEquals(1235960, money,1.0);
} @Test
public void testStock(){
Calculator4 k=new Calculator4();
double money=1000000;
double sum=3000000;
double rate=0.03;
int years;
years=(int) ((Math.log(sum)/Math.log(1+rate))-(Math.log(money)/Math.log(1+rate)));
System.out.println("years="+years);
Assert.assertEquals(37, years,1.0);
} @Test
public void testRate(){
Calculator4 k=new Calculator4();
double money=1000000;
double sum=3000000;
int years=30;
double rate;
rate=sum/(money*years);
System.out.println("rate="+rate);
Assert.assertEquals(0.1, rate,1.0);
} @Test
public void testAssets(){
Calculator4 k=new Calculator4();
double money=1000000;
double rate=0.03;
int years=30;
double sum1;
sum1=money*rate*years;
System.out.println("sum1="+sum1);
Assert.assertEquals(900000.0, sum1,1.0);
} @Test
public void testRepayment(){
Calculator4 k=new Calculator4();
double money=1000000;
double rate=0.03;
int years=10;
double sum2;
double i=rate/12;
int month=years*12;
sum2=money*i*Math.pow(1+i, month)/(Math.pow(1+i,month)-1);
System.out.println("sum2="+sum2);
Assert.assertEquals(9656, sum2,1.0);
}
}
测试截图:

还是不太懂单元测试到底要怎么写,感觉自己写的单元测试是错的,但是实在是不知道要怎么写
Compound Interest Calculator4.0的更多相关文章
- Compound Interest Calculator3.0
Compound Interest Calculator3.0 1.利率这么低,复利计算收益都这么厉害了,如果拿100万元去买年报酬率10%的股票,若一切顺利,过多长时间,100万元就变成200万元呢 ...
- Compound Interest Calculator2.0
Compound Interest Calculator2.0 1.如果按照单利计算,本息又是多少呢? 2.假如30年之后要筹措到300万元的养老金,平均的年回报率是3%,那么,现在必须投入的本金是多 ...
- Compound Interest Calculator1.0
Compound Interest Calculator1.0 客户说:帮我开发一个复利计算软件. 计算:本金为100万,利率或者投资回报率为3%,投资年限为30年,那么,30年后所获得的利息收入:按 ...
- Compound Interest Calculator3.0续
1.你写的程序能让客户随意操作吗?误输入数据.不小心做了非常规的操作程序是什么反应? 2.如果向银行贷款10万元,年利率6.5%,期限为10年,那么每月等额本息还款多少?(算复利条件下等额还款金额) ...
- <更新日期03-31-2016> 复利计算5.0 <已改进>
作业要求: 1.客户说:帮我开发一个复利计算软件. 完成复利公式计算程序,并成功PUSH到github上. 客户提出: 2.如果按照单利计算,本息又是多少呢? 3.假如30年之后要筹措到300万元的养 ...
- DL4J (DeepLearning for java)
http://deeplearning4j.org/lstm.html A Beginner’s Guide to Recurrent Networks and LSTMs Contents Feed ...
- 数学常数e的含义
转载: http://www.ruanyifeng.com/blog/2011/07/mathematical_constant_e.html 作者: 阮一峰 日期: 2011年7月 9日 1. ...
- linux下的文本处理命令sed&awk&grep
Sedsed 是个精简的.非交互式的编辑器.他能执行和编辑vi和emacs相同的编辑任务.sed编辑器不提供交互使用方式:只能在命令行输入编辑命令.指定文件名,然后在屏幕上察看输出.sed编辑器没有破 ...
- C程序练习
1.编程从键盘任意输入两个时间(例如4时55分和1时25分),计算并输出这两个时间之间的间隔.要求不输出时间差的负号. #include<stdio.h> int main() { int ...
随机推荐
- UVA 11404 五 Palindromic Subsequence
Palindromic Subsequence Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu ...
- CodeForces 508C Anya and Ghosts
Anya and Ghosts Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- Windows控制台程序“选定模式”的问题
最近用Nodejs写了个代理程序,一直用的好好的,木有问题,今天突然发现不能用了,使用telnet去连代理的端口也能连通,可是服务就是不能正常使用,提示连接超时. 当时猜测是Nodejs的某个地方阻塞 ...
- MySQL占用内存过大的问题解决
MySQL竟然变化这么大了,记忆里还是40MB左右的软件. 想找回记忆里大小的软件(老版本的软件),可以去这个地址看看:http://mirrors.soho.com 现在去官网下载都300多MB了… ...
- Highlighting Text Item On Entry In Oracle Forms
Highlight a Text Item in Oracle Forms With Visual Attribute It is very necessary to highlight the cu ...
- kaili 2.0 开启ssh远程
第一步:更改sshd_config文件
- 关于js运动的一些总结
js运动实现,有两种.一种是速度版,另一种是时间版. 速度版是通过对速度的加减乘除,得出元素的运动数据.时间版是通过对时间进行Tween公式运算,得出元素的运动数据. 速度版运动优点:容易在运动过程中 ...
- 转载java源代码阅读方法
刚才在论坛不经意间,看到有关源码阅读的),不禁又有一种激动. 源码阅读,我觉得最核心有三点:技术基础+强烈的求知欲+耐心. 说到技术基础,我打个比方吧,如果你从来没有学过Java,或是任何一门编程语言 ...
- 利用JDK的中Proxy动态代理实现Spring的AOP技术
首先给出设计模式静态代理与动态代理的学习: http://layznet.iteye.com/blog/1182924 讲的不错 然后我们实现AOP 就要求我们对委托的所有方法的调用实现拦截 代理 ...
- linux设备驱动编写_tasklet机制(转)
在编写设备驱动时, tasklet 机制是一种比较常见的机制,通常用于减少中断处理的时间,将本应该是在中断服务程序中完成的任务转化成软中断完成. 为了最大程度的避免中断处理时间过长而导致中断丢失,有时 ...