练习5.1更新——四则运算 测试与封装
2015-04-30 15:50
288 查看
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 进行测试.(由于电脑屏幕小,只截取大部分.)
因为是第一次做这种测试单元,所以有很多不足的地方,以后会慢慢改进的.
相关文章推荐
- 练习5.1更新——四则运算 测试与封装
- 练习5.1——四则运算 测试与封装(更新版)
- 练习5.1——四则运算 测试与封装
- 作业5 四则运算 测试与封装 5.1
- 作业5 四则运算 测试与封装 5.1
- 四则运算 测试与封装5.1
- 作业5 四则运算 测试与封装 5.1
- 四则运算 测试与封装 5.1
- 作业5 四则运算 测试与封装 5.1
- 作业5 四则运算 测试与封装 5.1
- 作业5 四则运算 测试与封装 5.1
- 【作业报告】作业5 四则运算 测试与封装 5.1 改进版
- 四则运算 测试与封装 5.1结队
- 作业5 四则运算 测试与封装 5.1
- 四则运算 测试与封装 5.1
- 20150421 作业5 四则运算 测试与封装 5.1
- 作业5 四则运算 测试与封装 5.1
- 5.1作业5 四则运算 测试与封装
- 作业5 四则运算 测试与封装 5.1 5.2
- 四则运算测试与封装5.1 结对