标签:
测试用例 |
||
序号 | 测试输入:三条边(a,b,c) | 测试预言(Oracle:直角、等腰、等边三角形) |
1 | 输入(1,1,1) | 等边三角形 |
2 | 输入(3, 4,5) | 直角三角形 |
3 | 输入(2, 2,1) | 等腰三角形 |
4 | 输入(3, 3,6) | 不是三角形 |
5 | 输入(3, -3,6) | 非法 |
6 | 输入(-3, 3,6) | 非法 |
感想:等价类划分法是一种典型的、重要的黑盒测试方法,它将程序所有可能的输入数据(有效的和无效的)划分成若干个等价类。然后从每个部分中选取具有代表性的数据当做测试用例进行合理的分类。合理的用好等价类划分法能节约测试时间。
github账号:https://github.com/hjs12
public class Triangle { // 定义三角形的三边 protected long lborderA = 0; protected long lborderB = 0; protected long lborderC = 0; // 构造函数 public Triangle(long lborderA, long lborderB, long lborderC) { this.lborderA = lborderA; this.lborderB = lborderB; this.lborderC = lborderC; } /** * 判断是否是三角形 * * 是返回true;不是返回false */ public boolean isTriangle(Triangle triangle) { boolean isTriangle = false; // 判断边界,大于0 小于或等于Long.MAX_VALUE,出界返回false if ((triangle.lborderA > 0 && triangle.lborderA <= Long.MAX_VALUE) && (triangle.lborderB > 0 && triangle.lborderB <= Long.MAX_VALUE) && (triangle.lborderC > 0 && triangle.lborderC <= Long.MAX_VALUE)) { // 判断两边之差小于第三边 if (diffOfBorders(triangle.lborderA, triangle.lborderB) < triangle.lborderC && diffOfBorders(triangle.lborderB, triangle.lborderC) < triangle.lborderA && diffOfBorders(triangle.lborderC, triangle.lborderA) < triangle.lborderB) { isTriangle = true; } } return isTriangle; } /** * 判断三角形类型 * * 只有两条边相等的三角形返回字符串“等腰三角形”; 三边均相等的三角形返回字符串“等边三角形”; 三边均不等的三角形返回字符串“不等边三角形”; */ public String getType(Triangle triangle) { String strType = "Illegal"; // 判断是否是三角形 if (isTriangle(triangle)) { // 判断是否是等边三角形 if (triangle.lborderA == triangle.lborderB && triangle.lborderB == triangle.lborderC) { strType = "Regular"; } // 判断是否是不等边三角形 else if ((triangle.lborderA != triangle.lborderB) && (triangle.lborderB != triangle.lborderC) && (triangle.lborderA != triangle.lborderC)) { strType = "Scalene"; } // 三角形既非三边全部相等,又非全部不等,只能是部分相等即等腰三角形 else { strType = "Isoceles"; } } return strType; } /** * 计算两边之差的绝对值 * * */ public long diffOfBorders(long a, long b) { return (a > b) ? (a - b) : (b - a); } @Test public void testIsTriangle1(){ Triangle t = new Triangle(1,1,1); assertFalse(t.isTriangle(t)); } @Test public void testIsTriangle2(){ // according to the mutant, this test case should fail Triangle t = new Triangle(3,4,5); assertFalse(t.isTriangle(t)); } @Test public void testIsTriangle3(){ Triangle t = new Triangle(2,2,1); assertFalse(t.isTriangle(t)); } @Test public void testIsTriangle4(){ Triangle t = new Triangle(3,3,6); assertFalse(t.isTriangle(t)); } @Test public void testIsTriangle5(){ Triangle t = new Triangle(3,-3,6); assertFalse(t.isTriangle(t)); } @Test public void testIsTriangle6(){ Triangle t = new Triangle(-3,3,6); assertFalse(t.isTriangle(t)); } /** * 用于获取三角形的边长 */ public long[] getBorders() { long[] borders = new long[3]; borders[0] = this.lborderA; borders[1] = this.lborderB; borders[2] = this.lborderC; return borders; }
标签:
原文地址:http://www.cnblogs.com/hjss/p/5503569.html