具体内容以视频形式发布在b站
代码1:
public class Triangle {
public static int getType(int a,int b,int c) {
if(a+b>c && a+c>b &&b+c>a) {//判定1
if(ab &&bc ) { //判定2
return 3;// 等边三角形
}
else if(a!=b && b!=c && a!=c) {//判定3
return 1;// 普通三角形
}
else {
return 2;// 等腰三角形
}
}
else {
return 0;// 非三角形
}
}
}
代码2:
标签:Triangle,int,代码,getType,Should,实验,&&,triangle,Junit5 From: https://www.cnblogs.com/sshuangjiangg/p/18235018import Junit5.Triangle;
import static org.junit.jupiter.api.Assertions.*;
class TriangleTest {
@org.junit.jupiter.api.Test
void getType() {
assertAll("triangleTypeTests",
() -> assertEquals(3, Triangle.getType(2, 2, 2), "Should be an equilateral triangle"),
() -> assertEquals(1, Triangle.getType(3, 4, 5), "Should be a scalene triangle"),
() -> assertEquals(2, Triangle.getType(2, 3, 3), "Should be an isosceles triangle"),
() -> assertEquals(0, Triangle.getType(1, 1, 2), "Should not be a triangle")
);
}