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



// 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 (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; return TriangleType.NORMAL;
} }
System.out.println("Kein Dreieck");
return TriangleType.NONE; return TriangleType.NONE;
} }



+ 15
- 0
test/TriangleCheckerTest.java View File

// Assert // Assert
assertEquals(TriangleChecker.TriangleType.NORMAL, type); 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