Browse Source

Solution 16.12.2021 15:02

master
Felix Schmidt 2 years ago
parent
commit
728393f22f
2 changed files with 26 additions and 1 deletions
  1. 11
    1
      src/TriangleChecker.java
  2. 15
    0
      test/TriangleCheckerTest.java

+ 11
- 1
src/TriangleChecker.java View File

@@ -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;
}


+ 15
- 0
test/TriangleCheckerTest.java View File

@@ -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);

}

}

Loading…
Cancel
Save