zoukankan      html  css  js  c++  java
  • 0329 单元测试:复利计算器 (组员:韩麒麟 列志华)

    测试要求:

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

       有哪些场景?

       期待的返回值

       写测试程序

       运行测试

    场景演示

    1. 结果是否正确?

    2. 数值为空是怎么办?

    3.输入负数是否准确?

    4.是否满足性能要求?

    场景1. 结果是否正确?

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

    结果:

    代码如下:

    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

  • 相关阅读:
    微信公众号 发送客服消息
    juqery 点击谁获取他的值,赋给input标签
    微信执行退出页面,直接回到微信对话窗口
    微信jssdk上传图片,一张一张的上传 和 一次性传好几张
    juqery 判断所有input 不能为空 判断只能为数字 判断身份证号:18位和15位 判断是否银行卡号
    php foreach
    现在越来越喜欢用ajax传值了,这样能让网站的体验性很好,今天就总结了一下常用的
    有时候不用explode截取字符串了,可以用用substr()
    ztree 文件夹类型的 树状图
    POJ 1065 Wooden Sticks
  • 原文地址:https://www.cnblogs.com/hanqilin/p/5335115.html
Copyright © 2011-2022 走看看