zoukankan      html  css  js  c++  java
  • 练习5.1更新——四则运算 测试与封装

    package com.h1;
    
    import static org.junit.Assert.*;
    
    import org.junit.Assert;
    import org.junit.Before;
    import org.junit.Test;
    
    import com.h2.Core;
    
    public class CoreTest {    
        @Test
        public void testAdd() {// 加法
            int n = 3;// 操作数个数
            int[] num1 = { 1, 2, 3 };// 操作数
            char[] op = {' ', '+', '-', '*', '/' };// 操作符
            int[] no = { 1, 1 };// 操作符下标
            Core c = new Core();
            c.calcute(num1,op,no,n);// 运算1+2+3
            int r = (int) c.getResult();
            System.out.println(r);
            assertEquals(6, r);
        }
        
        @Test
        public void testJian() {// 减法
            int n = 3;// 操作数个数
            int[] num1 = { 1, 2, 3 };// 操作数
            char[] op = { ' ', '+', '-', '*', '/' };// 操作符
            int[] no = { 2, 2 };// 操作符下标
            Core c = new Core();
            c.calcute(num1, op, no, n);// 运算1-2-3
            int r = (int) c.getResult();
            System.out.println(r);
            assertEquals(-4, r);
        }
        
        @Test
        public void testMulti() {// 乘法
            int n = 3;// 操作数个数
            int[] num1 = { 2, 2, 3 };// 操作数
            char[] op = { ' ', '+', '-', '*', '/' };// 操作符
            int[] no = { 3, 3 };// 操作符下标
            Core c = new Core();
            c.calcute(num1, op, no, n);// 运算2*2*3
            int r = (int) c.getResult();
            System.out.println(r);
            assertEquals(12, r);
        }
        
        @Test
        public void testDiv() {// 除法
            int n = 2;// 操作数个数
            int[] num1 = { 2, 2, 3 };// 操作数
            char[] op = { ' ', '+', '-', '*', '/' };// 操作符
            int[] no = { 4 };// 操作符下标
            Core c = new Core();
            c.calcute(num1, op, no, n);// 运算2/2
            double r =  c.getResult();
            System.out.println(r);
            assertEquals(1, r,100);
        }
        
        @Test(expected = ArithmeticException.class)
        public void testZero() {// 除以零
            int n = 3;// 操作数个数
            int[] num1 = { 1, 0, 3 };// 操作数
            char[] op = { ' ', '+', '-', '*', '/' };// 操作符
            int[] no = { 4, 1 };// 操作符下标
            Core c = new Core();
            c.calcute(num1, op, no, n);// 运算1/0+3
        }
        
        @Test
        public void testNormal() {// 混合运算
            int n = 5;// 操作数个数
            int[] num1 = { 1, 2, 3, 4 ,4 };// 操作数
            char[] op = { ' ', '+', '-', '*', '/' };// 操作符
            int[] no = { 1, 3,2,4 };// 操作符下标
            Core c = new Core();
            c.calcute(num1, op, no, n);// 运算1+2*3
            int r = (int) c.getResult();
            System.out.println(r);
            assertEquals(6, r);
        }
        
        
    
    }
    测试类

    -这次作业和我的伙伴林焕雯一起完成,详细的测试代码在这里http://www.cnblogs.com/wzhz/

    -(1)黑盒子测试.这个测试主要就是以用户角度测试代码的功能与用途,以及存在的一些和外部环境相关的问题.如下图:

    -(2)白盒子测试。对软件的过程性细节做细致的检查。这一方法是把测试对象

       看作一个打开的盒子,它允许测试人员利用程序内部的逻辑
       结构及有关信息,来设计或选择测试用例,对程序所有逻辑
       路径进行测试。这里用条件覆盖 对路径进行覆盖测试.这里主要是对具有计算功能的一个模块Core 进行测试.(由于电脑屏幕小,只截取大部分.)
    因为是第一次做这种测试单元,所以有很多不足的地方,以后会慢慢改进的.
     
  • 相关阅读:
    mysql 自定义排序
    arcgis 好人
    eclipse启动tomcat,提示三个端口均被占用
    oracle 查看表空间创建日期
    navacat 链接oracle oci invalid handle
    java +mysql 递归排序/* START WITH aa.parentid IN ( 10000, 20000, 30000, 40000, 50000, 60000, 70000 ) connect BY prior aa.id = aa.parentid ORDER siblings BY aa.id ASC*/ to
    Double 转 BigDecimal
    mysql 死锁 Waiting for stored function metadata lock
    Graphtree--zabbix增强功能(一屏展示所有内容)
    zabbix 分布式监控(proxy)源码安装
  • 原文地址:https://www.cnblogs.com/be-the-one/p/4469104.html
Copyright © 2011-2022 走看看