单元测试代码0330
2016-03-30 20:25
260 查看
package compounding; import static org.junit.Assert.*; import junit.framework.Assert; import org.junit.Before; import org.junit.Test; public class compounding1_2Test { compounding1_1 test; @Before public void setUp() throws Exception { test =new compounding1_1(); } @Test public void testPrincipal() { //fail("尚未实现"); double q=0.03; double P; int year=3,n=2; double F=20000; P = F / Math.pow((1 + q / n), year * n); //Assert.assertEquals(18290.843850357436, 18290.843850357436,0.0); assertEquals(18290.88, 18290.843850357436,0.02); } @Test public void testYear_end_value() { //fail("尚未实现"); double q=0.03; double P=10000; int year=10,n=2; double F; F=P * Math.pow((1 + q / n), year * n); assertEquals(13468,13468.6,1.0); } @Test public void testDanli() { // fail("尚未实现"); int year=10; double q=0.03, F, P=10000; F = P + P * year * q; Assert.assertEquals(13468,13468.6,1.0 ); } @Test public void testYears() { // fail("尚未实现"); int year, n=2; double q=0.03, F=20000, P=10000; year = (int) (Math.log(F / P) / Math.log(1 + q /n) / n); assertEquals(23, 23.45,1.0); } @Test public void testAPY() { // fail("尚未实现"); int year=3, n=2; double q, F=20000, P=10000; q = n * (Math.pow(F / P, 1.0 / (year * n)) - 1); assertEquals(0.26,0.24492409661874603,0.01 ); //assertEquals(0.24492409661874603,0.24492409661874603,0.0 ); } @Test public void testInvestmentyear() { // fail("尚未实现"); int year=10, n=2; double q=0.03, final_value, P=10000; final_value = P * (Math.pow(1 + q, year) - 1) /q; assertEquals(13468, 13468.60,1.0); } @Test public void testInvestmentmonth() { // fail("尚未实现"); int year=10, n=2; double q=0.03, final_value, P=10000; final_value = P * 12 * (1 + q) * (Math.pow(1 + q, year) - 1) / q; assertEquals(13468, 13468.60,1.0); } @Test public void testRepayment() { // fail("尚未实现"); int year=10; double q=0.03, F=20000, refund; refund = F * q / (12 * (1 + q) * (Math.pow(1 + q, year) - 1)); assertEquals(1000,1000.50,1.0 ); } }
相关文章推荐
- delphi中用代码实现注册Ocx和Dll(有点怪异,使用CallWindowProc来调用指定函数DllRegisterServer)
- 0330复利计算java版
- 106 miles to Chicago---zoj2797(最短路问题,求概率,模板)
- 关于C和c++中的文件结构
- 模拟抽奖的九宫格动画效果
- Go语言学习六:指针与传递到函数的指针
- java 基础拾遗
- c++函数重载
- matlab 结构体struct
- java collection接口笔记
- 单元测试代码
- Github安装失败主要是因为.net framework 4.0安装失败
- delphi 控件大全(确实很全)
- LeetCode 22. Generate Parentheses
- Java Web项目中解决中文乱码方法总结
- 基本排序算法java实现之选择排序
- Spring 面试题
- java GC、新生代、老年代
- c++使用心得
- C++组合应用之strtok字符串分割、数组平分算法、动态数组函数传参