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 ...
随机推荐
- C#变量与数据类型
数据类型: 整型:int short long byte 小数:double float decimal 布尔:bool 字符:char 定义变量: 数据类型 变量名 [= 值]; 变量名的命名规则: ...
- UE4编程之C++创建一个FPS工程(二)角色网格、动画、HUD、子弹类
转自:http://blog.csdn.net/u011707076/article/details/44243103 紧接上回,本篇文章将和大家一同整理总结UE4关于角色网格.动画.子弹类和HUD的 ...
- HashCheck
https://github.com/gurnec/HashCheck
- HQL语句大全(转载)
Hibernate配备了一种非常强大的查询语言,这种语言看上去很像SQL.但是不要被语法结构 上的相似所迷惑,HQL是非常有意识的被设计为完全面向对象的查询,它可以理解如继承.多态 和关联之类的概念. ...
- python_way,day8 面向对象【多态、成员--字段 方法 属性、成员修饰符、特殊成员、异常处理、设计模式之单例模式、模块:isinstance、issubclass】
python_way day8 一.面向对象三大特性: 多态 二.面向对象中的成员 字段.方法属性 三.成员修饰符 四.特殊成员 __init__.__doc__.__call__.__setitem ...
- hdu 5137 How Many Maos Does the Guanxi Worth 最短路 spfa
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- POJ1088滑雪(记忆化搜索+DFS||经典的动态规划)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 84297 Accepted: 31558 Description M ...
- updatePanel导致JS失效的解决办法(转)
吐槽下,维护别人之前做的项目好蛋疼,整个页面都是用微软的ajax框架. 今天给repeater用JS写一个hover事件 <script type="text/javascript&q ...
- SecureCRT显示中文和语法高亮
因为默认情况下,SecureCRT不能显示语法高亮特性,整个界面颜色单一,看起来不爽,也没有效率,所有通过设置一下语法高亮还是很有必要的, 默认字体也看着不是很清晰,还是更改为我比较喜欢的Courie ...
- 什么是Plist文件
直接将数据直接写在代码里面,不是一种合理的做法.如果数据经常改,就要经常翻开对应的代码进行修改,造成代码扩展性低 因此,可以考虑将经常变的数据放在文件中进行存储,程序启动后从文件中读取最新的数据.如果 ...