复利计算器Junit单元测试
一。测试场景
| 测试模块 | 测试输入 | 预期结果 | 运行结果 | bug跟踪 |
| 复利计算 |
(本金,利率,年限,次数) |
终值 |
||
|
测试运算结果 |
(100,5,3,1) | 115.76 | 115.76 | |
| 测试输入负数 | (-100,5,3,1) | False | False | |
| 测试输入0 | (0,5,3,1) | False | False | |
| 单利计算 | (本金,利率,年限) |
终值 |
||
|
测试运算结果 |
(1000,2,5) | 1100 | 1100 | |
| 测试输入负数 | (-1000,2,5) | False | False | |
| 测试输入0 | (0,2,5) | False | False | |
| 本金估算 | (终值,利率,年限,次数) | 本金 | ||
|
测试运算结果 |
(1000,2,5,1) | 905.73 | 905.73 | |
| 测试输入负数 | (-1000,2,5,1) | False | False | |
| 测试输入0 | (0,2,5,1) | False | False | |
| 年限估算 | (本金,利率,次数,终值) | 年限 | ||
|
测试运算结果 |
(1000,2,1,2000) | 35 | 35 | |
| 测试输入负数 | (-1000,-2,1,2000) | False | False | |
| 测试输入0 | (0,2,1,2000) | False | False | |
| 利率估算 | (本金,年限,次数,终值) | 利率 | ||
|
测试运算结果 |
(1000,5,1,2000) | 14.86 | 14.86 | |
| 测试输入负数 | (-1000,-5,1,2000) | False | False | |
| 测试输入0 | (0,0,1,2000) | False | False | |
| 按年投资 | (年投资额,利率,定投年数) | |||
|
测试运算结果 |
(1000,2,5) | 5308.12 | 5308.12 | |
| 测试输入负数 | (-1000,2,5) | False | False | |
| 测试输入0 | (0,2,5) | False | False | |
| 按月投资 | (月投资额,利率,定投月数) | |||
|
测试运算结果 |
(1000,2,6) | 6035.09 | 6035.09 | |
| 测试输入负数 | (-1000,2,6) | False | False | |
| 测试输入0 | (0,2,6) | False | False | |
| 等额本息还款 | (贷款金额,利率,年限,次数) | |||
|
测试运算结果 |
(10000,2,5,2) | 175.16 | 175.16 | |
| 测试输入负数 | (-10000,2,5,2) | False | False | |
| 测试输入0 | (0,2,5,2) | False | False |
二。测试代码
import static org.junit.Assert.*; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; public class test {
@Before
public void setUp() throws Exception {
}
@org.junit.Test
public void testCompound() {
CompoundCalculator Compound = new CompoundCalculator();
double F = Compound.Compound(100,5,3,1);
Assert.assertEquals(F, 115.76, 1.0);
// assertTrue(F>0);
double f =Compound.Compound(-100,5,3,1);
assertFalse(f>0);
double a=Compound.Compound(0,5,3,1);
assertFalse(a>0);
}
@org.junit.Test
public void testSimple() {
CompoundCalculator Simple = new CompoundCalculator();
double F = Simple.Simple(1000,2,5);
Assert.assertEquals(F, 1100, 0.0);
// assertTrue(F>0);
double f =Simple.Simple(-1000,2,5);
assertFalse(f>0);
double a=Simple.Simple(0,2,5);
assertFalse(a>0);
}
@org.junit.Test
public void testPrinciple() {
CompoundCalculator Principle = new CompoundCalculator();
double F = Principle.Principle(1000,2,5,1);
Assert.assertEquals(F, 905.73, 1.0);
// assertTrue(F>0);
double f =Principle.Principle(-1000,2,5,1);
assertFalse(f>0);
double a=Principle.Principle(0,2,5,1);
assertFalse(a>0);
}
@org.junit.Test
public void testYear() {
CompoundCalculator Year = new CompoundCalculator();
double F = Year.Year(1000,2,1,2000);
Assert.assertEquals(F, 35, 0.0);
// assertTrue(F>0);
double f =Year.Year(-1000,-2,1,2000);
assertFalse(f>0);
double a=Year.Year(0,2,1,2000);
assertFalse(a<0);
}
@org.junit.Test
public void testRate() {
CompoundCalculator Rate = new CompoundCalculator();
double F = Rate.Rate(1000,5,1,2000);
Assert.assertEquals(F, 14.86, 1.0);
// assertTrue(F>0);
double f =Rate.Rate(-1000,-5,1,2000);
assertFalse(f>0);
double a=Rate.Rate(0,0,1,2000);
assertFalse(a<0);
}
@org.junit.Test
public void testYearinvest() {
CompoundCalculator Yearinvest = new CompoundCalculator();
double F = Yearinvest.Yearinvest(1000,2,5);
Assert.assertEquals(F, 5308.12, 1.0);
// assertTrue(F>0);
double f =Yearinvest.Yearinvest(-1000,2,5);
assertFalse(f>0);
double a=Yearinvest.Yearinvest(0,2,5);
assertFalse(a>0);
}
@org.junit.Test
public void testMonthinvest() {
CompoundCalculator Monthinvest = new CompoundCalculator();
double F = Monthinvest.Monthinvest(1000,2,6);
Assert.assertEquals(F, 6035.09, 1.0);
// assertTrue(F>0);
double f =Monthinvest.Monthinvest(-1000,2,6);
assertFalse(f>0);
double a=Monthinvest.Monthinvest(0,2,6);
assertFalse(a>0);
}
@org.junit.Test
public void testRepayment() {
CompoundCalculator Repayment = new CompoundCalculator();
double F = Repayment.Repayment(10000,2,5,2);
Assert.assertEquals(F, 175.16, 1.0);
// assertTrue(F>0);
double f =Repayment.Repayment(-10000,2,5,2);
assertFalse(f>0);
double a=Repayment.Repayment(0,2,5,2);
assertFalse(a>0);
} }
三。测试结果

复利计算器Junit单元测试的更多相关文章
- 复利计算器4.0之再遇JUnit
复利计算器4.0之再遇JUnit 前言 虽然之前的复利计算器版本已经尝试过使用JUnit单元测试,但由于没有系统性地学习过JUnit的使用,用得并不好,主要问题表现在测试的场景太少,并没有达到测 ...
- 基础-Junit单元测试_反射_注解
一.Junit单元测试 1.1 测试分类: 黑盒测试:不需要写代码,给输入值,看程序是否能够输出期望的值. 白盒测试:需要写代码的.关注程序具体的执行流程. 1.2 Junit使用(白盒测试) 使用步 ...
- 复利计算器(4)——jQuery界面美化、自动补全
一.分工 这次终于可以跟小伙伴合作了,经过讨论,我负责界面的美化和输入框自动补全,小伙伴擅长安卓,于是将复利计算器弄成app的任务就交给了小伙伴.为了我们两人团队,我们都好奋斗哈哈哈!! 二.界面美化 ...
- junit单元测试(keeps the bar green to keeps the code clean)
error是程序错误,failure是测试错误. junit概要: JUnit是由 Erich Gamma (设计模式的创始人)和 Kent Beck (敏捷开发的创始人之一)编写的一个回归测试框架( ...
- spring && Cobertura && maven &&junit 单元测试以及测试覆盖率
1. 目的: junit 单元测试,Cobertura 测试覆盖率报告 项目目录结构 2. maven 配置 <project xmlns= ...
- 复利计算器v1
public class MainFrame extends JFrame { /** * 文本框 */ private TextField[] texts = new TextField[5]; / ...
- java版复利计算器升级
github地址:https://github.com/iamcarson/Carson 伙伴:彭宏亮 学号:201406114148 与伙伴工作帅照: 本次升级的地方: 1.改善了界面显示,让界面整 ...
- 0406.复利计算器5.0版-release
复利计算器5.0-release 目录 项目简介 Github链接推送 客户需求 新增需求分析 项目设计 效果演示 操作说明 程序结构 结对分工 合作照片 总结 1.项目简介 项目名称:复利计算器 目 ...
- 解决Junit单元测试 找不到类 ----指定Java Build Path
做junit 单元测试时,发现怎么执行都是以前编译过得代码. 最后找到原因了, src/test/java 编译完的.class路径是 Default output folder Default ou ...
随机推荐
- 第一篇随笔, 正在做 ESP32 , STM32 , 树莓派 RaspberryPi 的创客工具
先随便写写一些思路, 以后再整理. 这段时间笔者做了一些硬件开发, 领悟了一些事情. 1 - 在常规创客的角度上, 硬件开发所需的知识面比较广, 非常广, 但不算太深. 2 - 发现硬件开发由于其特殊 ...
- BurpSuite—-Repeater模块(中继器)
一.简介 Burp Repeater 是一个手动修改并补发个别 HTTP 请求,并分析他们的响应的工具.它最大的用途就是和其他 Burp Suite 工具结合起来.你可以从目标站点地图,从 Burp ...
- Go语言的包管理
1 概述 Go 语言的源码复用建立在包(package)基础之上.包通过 package, import, GOPATH 操作完成. 2 main包 Go 语言的入口 main() 函数所在的包(pa ...
- 5.18-笨办法学python-习题14
有了习题13的基础,习题14就不是问题了. 这一节主要是一个简单的提示符.提示符就是像">"这个的东西,因为我们之前用input的时候,它是用来让用户输入的,可是平常人并不知 ...
- Bessel函数的零点计算 MATLAB
由于MATLAB自己没有附带贝塞尔函数零点,因此使用起来很不方便,特别是在绘制仿真场量时. 下面给出0-9阶的贝塞尔函数零点的计算公式,其中理论上计算零点个数N在50以内时较为精确: function ...
- 20155302 2016-2017-2 《Java程序设计》第3周学习总结
20155302 2016-2017-2 <Java程序设计>第3周学习总结 教材学习内容总结 两个基本的标准类:java.util.Scanner与java.math.BigDecima ...
- 小程序if else 判断显示隐藏
wxml: <view> <text wx:if="{{ifnumber>80}}">{{ifnumber}}</text> <te ...
- JDK1.7的HashMap的put(key, value)源码剖析
目录 HashMap的put操作源码解析 1.官方文档 2.put(key, value) 3.完结 HashMap的put操作源码解析 1.官方文档 1.1.继承结构 java.lang.Objec ...
- 【MongoDB】NoSQL Manager for MongoDB 教程(进阶篇)
项目做完,有点时间,接着写下第二篇吧.回顾戳这里 基础篇:安装.连接mongodb.使用shell.增删改查.表复制 本文属于进阶篇,为什么叫进阶篇,仅仅是因为这些功能属于DB范畴,一般使用的不多, ...
- sqlite3日期数据类型
一.sqlite3日期数据类型,默认用datetime解析(根据stackflow) 使用时注意三点: 1. 创建表时,字段 DT 的类型为 date 2. 插入数据时,DT字段直接为 str 类型 ...