软件测试大赛开发者测试Triangle题目
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/583cfe3f87e15cca09f86c5a35648280.png)
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
//1.更改默认的测试运行器为Parameterized.class
@RunWith(Parameterized.class)
public class TriangleTest {
//2.声明变量存放输入值,预期值
//输入值
long a,b,c;
//预期值
Boolean isT;
String type;
long diffAAndB;
long diffAAndC;
long[] borders;
//3.声明返回值为数组的方法,并用@Paramters修饰
@Parameters
public static Collection data() {
return Arrays.asList(new Object[][] {
//无效等价类
{0,3,3,"Illegal",false,3,3},
//有效等价类
//isT:
{3,3,3,"Regular",true,0,0},
{1,2,3,"Illegal",false,1,2},
//type
{1,2,2,"Isosceles",true,1,1},
{5,4,3,"Scalene",true,1,2}
});
}
//4.为测试类声明一个带参构造函数,为变量赋值
public TriangleTest(long a,long b,long c,String type,Boolean isT,long diffAAndB,long diffAAndC) {
this.a = a;
this.b = b;
this.c = c;
this.type = type;
this.isT = isT;
this.diffAAndB = diffAAndB;
this.diffAAndC = diffAAndC;
this.borders = new long []{a,b,c};
}
//5.编写测试类
@Test
public void testIsT() throws Exception{
Triangle T = new Triangle(a,b,c);
assertEquals(isT,T.isTriangle(T));
}
@Test
public void testTType() throws Exception{
Triangle T = new Triangle(a,b,c);
assertEquals(type,T.getType(T));
}
@Test
public void testdiffOfBordersAndgetBorders() throws Exception{
Triangle T = new Triangle(a,b,c);
long[] borders1 = T.getBorders();
assertArrayEquals(this.borders,borders1);
assertEquals(diffAAndB,T.diffOfBorders(borders1[0],borders1[1]));
assertEquals(diffAAndC,T.diffOfBorders(borders1[0],borders1[2]));
}
}