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 ...
随机推荐
- CodeForces 490C Hacking Cypher
Hacking Cypher Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Sub ...
- [HDOJ5783]Divide the Sequence(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5783 题意:给n个数,要求划分成多个段,使得每一个段的任意前缀和都不小于0. 从后往前截取,这样不会影 ...
- 对MSP430单片机__delay_cycles精确延时的说明及改正
在这里, 我来讨论一下关于MSP430单片机使用__delay_cycles延时的问题. IAR for MSP430编译器提供了一个编译器内联的精确延时函数(并非真正的函数)以提供用户精确延时使用, ...
- 观摩制作小游戏(js应用)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- hashcat
作者: 官网:https://hashcat.net/oclhashcat/ 功能:hash破解
- FJNU 1151 Fat Brother And Geometry(胖哥与几何)
FJNU 1151 Fat Brother And Geometry(胖哥与几何) Time Limit: 1000MS Memory Limit: 257792K [Description] [ ...
- 2.mybatis入门实例 连接数据库进行查询
1.新建项目,添加mybatis和mysql的jar包 2.在mysql中新建表user[id,name,age] CREATE TABLE `users` ( `id` ) NOT NULL aut ...
- NoSQL系列:选择合适的数据库
NoSQL系列:选择合适的数据库 为什么使用NoSQL数据库? 阻抗失衡 关系模型和内存中的数据结构不匹配 采用更为方便的数据交互方式提升开发效率 待处理的数据量很大 数据量超过关系型数据库的承载能力 ...
- git学习笔记10-新开发的功能不想要了-强行删除分支
添加一个新功能时,你肯定不希望因为一些实验性质的代码,把主分支搞乱了,所以,每添加一个新功能,最好新建一个feature分支,在上面开发,完成后,合并,最后,删除该feature分支. 现在,你终于接 ...
- 转 图片资源加密,Lua文件加密
游戏开发中常遇到资源保护的问题. 目前游戏开发中常加密的文件类型有:图片,Lua文件,音频等文件,而其实加密也是一把双刃剑. 需要安全那就得耗费一定的资源去实现它.目前网上也有用TexturePack ...