0329 单元测试:复利计算器 (组员:韩麒麟 列志华)

测试要求:

   对我们和复利计算程序,写单元测试。 

   有哪些场景?

   期待的返回值

   写测试程序

   运行测试

 

场景演示

1. 结果是否正确?

2. 数值为空是怎么办?

3.输入负数是否准确?

4.是否满足性能要求?

 

场景1. 结果是否正确?

功能数据名称具体数据期待值
单利计算本金,项目利率,年限,终值100,0.05,1,105true
-100,0.05,1,105false
复利计算本金,项目利率,年限,复利次数,终值100,0.05,1,1,105true
-100,0.05,1,1,105false
本金估算项目利率,年限,复利次数,终值,本金0.05,1,1,105,100true
0.05,1,1,-105,100false
。。。   
   

结果:

代码如下:

package com.Junit.test;

import static org.junit.Assert.*;
import interest.BestProject;
import interest.CompoundInterrest;
import interest.InterestTime;
import interest.PeriodicIncome;
import interest.Principal;
import interest.Refund;
import interest.SingleInterest;

public class Test {

    @org.junit.Test
    public void testCompoundInterrest() {
        double f = new CompoundInterrest("0.05","100.0","1","1").Interrest();
        assertEquals(105, (int)f);
    }
    @org.junit.Test
    public void testSingleInterest() {
        double f = new SingleInterest("0.05","100.0","1").Interest();
        assertEquals(105, (int)f);
    }
    @org.junit.Test
    public void testInterestTime() {
        int t = new InterestTime("0.05","100.0","105.0","1").Interrest();
        assertEquals(1, t);
    }
    @org.junit.Test
    public void testPeriodicIncome() {
        double f = new PeriodicIncome("0.01","100","1").Interrest();
        assertEquals(101, (int)f);
    }
    @org.junit.Test
    public void testPrincipal () {
        double f = new Principal("0.05","105.0","1","1").Interrest();
        assertEquals(100, (int)f);
    }
    @org.junit.Test
    public void testBestProject () {
        double f = new BestProject("200","100","1","1").Interrest();
        assertEquals(1, (int)f);
    }
    @org.junit.Test
    public void testRefund () {
        double f = new Refund("0.87","1200","3").Interrest();
        assertEquals(94, (int)f);
    }

}

场景2. 数值为空是怎么办?

场景图如下:

数值为空时,场景图如下:

代码如下:

if(jt1.getText().trim().equals("") || jt2.getText().trim().equals("") ||jt3.getText().trim().equals("") ){
                JOptionPane jo = new JOptionPane();
                jo.showMessageDialog(null,"请输入数值!");
            }    else {
                System.out.print("22222222222");
                interest ();
            }

 

本产品由本人与同伴一起完成!

心得感悟

在写程序的时候出现了许多错误,但都通过上网查找资料和与同伴商量解决了。同时在使用单元测试的时候也深深的感受到了单元测试检测程序的方便性,大大降低了程序员测试的工作量,提高了工作的效率!

详细代码:https://github.com/hanqilin/interest

转载于:https://www.cnblogs.com/hanqilin/p/5335115.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值