练习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 进行测试.(由于电脑屏幕小,只截取大部分.)
因为是第一次做这种测试单元,所以有很多不足的地方,以后会慢慢改进的.
 

转载于:https://www.cnblogs.com/be-the-one/p/4469104.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值