@@ -47,9 +47,19 @@ public class TriangleChecker { | |||
// Analyse der Dreiecksart | |||
public static TriangleType checkTriangle(float a, float b, float c) { | |||
if (a + b > c || b + c > a || a + c > b) { | |||
if (a + b > c && b + c > a && a + c > b) { | |||
if ( a == b && b == c) { | |||
System.out.println("Gleichseitiges Dreieck"); | |||
return TriangleType.EQUILATERAL; | |||
} | |||
if ( a == b || b == c || a == c) { | |||
System.out.println("Gleichschenkliges Dreieck"); | |||
return TriangleType.ISOSCELES; | |||
} | |||
System.out.println("Dreieck"); | |||
return TriangleType.NORMAL; | |||
} | |||
System.out.println("Kein Dreieck"); | |||
return TriangleType.NONE; | |||
} | |||
@@ -17,6 +17,21 @@ public class TriangleCheckerTest { | |||
// Assert | |||
assertEquals(TriangleChecker.TriangleType.NORMAL, type); | |||
a = 1; b = 1; c = 100; | |||
TriangleChecker.TriangleType type2 = TriangleChecker.checkTriangle(a, b, c); | |||
assertEquals(TriangleChecker.TriangleType.NONE, type2); | |||
a = 3; b = 3; c = 2; | |||
TriangleChecker.TriangleType type3 = TriangleChecker.checkTriangle(a, b, c); | |||
assertEquals(TriangleChecker.TriangleType.ISOSCELES, type3); | |||
a = 3; b = 3; c = 3; | |||
TriangleChecker.TriangleType type4 = TriangleChecker.checkTriangle(a, b, c); | |||
assertEquals(TriangleChecker.TriangleType.EQUILATERAL, type4); | |||
} | |||
} |