判断三角形的java程序:
package demo2; public class Triangle { private double a,b,c; public Triangle(double a,double b,double c){ this.a =a; this.b =b; this.c =c; } /* * return value description: * 1.等边三角形 * 2.等腰三角形 * 3.其他三角形 * -1.不是三角形 */ public int type(){ if(isTriangle()){ if(a==b&&b==c){ return 1; }else if(a==b||b==c||c==a){ return 2; }else return 3; } else return -1; } //auxiliary method which is used to predicate weather three number consist of a triangle or not private boolean isTriangle(){ if(Math.abs(a-b)<c&&Math.abs(a-c)<b&&Math.abs(b-c)<a &&(a+b>c)&& (a+c >b)&& (b+c >a) ) return true; return false; } } |
单个的测试用例:
package demo2; import static org.junit.Assert.*; import org.junit.Test; public class TriangleTest { @Test public void testType(){ Triangle triangle = new Triangle(12,12,4); assertEquals(2,triangle.type()); } } |
参数化的测试用例:
package demo2; @RunWith(value = Parameterized.class) |