// Analyse der Dreiecksart | // Analyse der Dreiecksart | ||||
public static TriangleType checkTriangle(float a, float b, float c) { | public static TriangleType checkTriangle(float a, float b, float c) { | ||||
if (checkTriangleType(a,b,c) ){ | |||||
if(a==b && a==c){return TriangleType.EQUILATERAL;} | |||||
if(a==b||b==c||a==c){return TriangleType.ISOSCELES;} | |||||
return TriangleType.NORMAL; | |||||
} | |||||
return TriangleType.NONE; | return TriangleType.NONE; | ||||
} | } | ||||
public static boolean checkTriangleType(float a, float b, float c) { | |||||
if (a <= 0 || b <= 0 || c <= 0) { | |||||
return false; | |||||
} | |||||
return (a + b > c && b + c > a && a + c > b); | |||||
} | |||||
} | } |
float a = 2; | float a = 2; | ||||
float b = 3; | float b = 3; | ||||
float c = 4; | float c = 4; | ||||
float d = 12; | |||||
float e = 32; | |||||
float f = 7; | |||||
float h = 11; | |||||
float g = 41; | |||||
float i = 4; | |||||
// Act | |||||
TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a, b, c); | |||||
// Assert | // Assert | ||||
assertEquals(TriangleChecker.TriangleType.NORMAL, type); | |||||
assertTrue(TriangleChecker.checkTriangleType(a, b, c)); | |||||
assertFalse(TriangleChecker.checkTriangleType(a, d, c)); | |||||
assertTrue(TriangleChecker.checkTriangleType(e, d, e)); | |||||
assertFalse(TriangleChecker.checkTriangleType(a, f, h)); | |||||
assertFalse(TriangleChecker.checkTriangleType(i, c, d)); | |||||
assertFalse(TriangleChecker.checkTriangleType(g, i, d)); | |||||
} | } | ||||