Browse Source

Check length, negative, equilateral, isosceles

05.11.2024
Peter Kessler 1 month ago
parent
commit
7a1fa585f9
2 changed files with 30 additions and 9 deletions
  1. 15
    8
      src/praktikum02/TriangleChecker.java
  2. 15
    1
      test/praktikum02/TriangleCheckerTest.java

+ 15
- 8
src/praktikum02/TriangleChecker.java View File

@@ -5,9 +5,7 @@ import java.util.Scanner;
public class TriangleChecker {

public enum TriangleType {
NONE,
NORMAL,
ISOSCELES, // Gleichschenklig
NONE, NORMAL, ISOSCELES, // Gleichschenklig
EQUILATERAL // Gleichseitig
}

@@ -49,13 +47,22 @@ public class TriangleChecker {

// Analyse der Dreiecksart
public static TriangleType checkTriangle(float a, float b, float c) {
if(a==b && a==c){
return TriangleType.EQUILATERAL;
if (a <= 0 || b <= 0 || c <= 0) {
return TriangleType.NONE;
}
else{
return TriangleType.NORMAL;

if (a + b <= c || a + c <= b || b + c <= a) {
return TriangleType.NONE;
}

if (a == b && b == c) {
return TriangleType.EQUILATERAL;
}
}

if (a == b || b == c || a == c) {
return TriangleType.ISOSCELES;
}

return TriangleType.NORMAL;
}
}

+ 15
- 1
test/praktikum02/TriangleCheckerTest.java View File

@@ -10,9 +10,23 @@ class TriangleCheckerTest {
void checkTriangle() {
assertEquals(TriangleChecker.TriangleType.NORMAL, TriangleChecker.checkTriangle(5, 6, 7));
}

@Test
void checkGleichseitig() {
assertEquals(TriangleChecker.TriangleType.EQUILATERAL, TriangleChecker.checkTriangle(1,1,1));
assertEquals(TriangleChecker.TriangleType.EQUILATERAL, TriangleChecker.checkTriangle(1, 1, 1));
}

@Test
void checkNegativ() {
assertEquals(TriangleChecker.TriangleType.NONE, TriangleChecker.checkTriangle(-1, 3, 5));
assertEquals(TriangleChecker.TriangleType.NONE, TriangleChecker.checkTriangle(3, 0, 5));
assertEquals(TriangleChecker.TriangleType.NONE, TriangleChecker.checkTriangle(3, 5, -10));
}
@Test
void checkLength() {
assertEquals(TriangleChecker.TriangleType.NONE, TriangleChecker.checkTriangle(20, 3, 5));
assertEquals(TriangleChecker.TriangleType.NONE, TriangleChecker.checkTriangle(10, 20, 10));
assertEquals(TriangleChecker.TriangleType.NONE, TriangleChecker.checkTriangle(1, 1, 60));
}

}

Loading…
Cancel
Save