Browse Source

Fertige Abgabe mit mehreren Tests

master
juleslepitschka 2 years ago
parent
commit
b0cc3ac20d
2 changed files with 79 additions and 10 deletions
  1. 34
    8
      src/TriangleChecker.java
  2. 45
    2
      test/TriangleCheckerTest.java

+ 34
- 8
src/TriangleChecker.java View File

@@ -1,10 +1,10 @@
import java.util.Scanner;

public class TriangleChecker {
public enum TriangleType {
NONE,
NORMAL,
NONE, // kein Dreieck
NORMAL, // Dreieck
ISOSCELES, // Gleichschenklig
EQUILATERAL // Gleichseitig
}
@@ -32,23 +32,49 @@ public class TriangleChecker {
switch (type) {
case NONE:
System.out.println("Kein Dreieck");
break;
break;
case NORMAL:
System.out.println("Dreieck");
break;
break;
case ISOSCELES:
System.out.println("Gleichschenkliges Dreieck");
break;
break;
case EQUILATERAL:
System.out.println("Gleichseitiges Dreieck");
break;
break;
}
}

// Analyse der Dreiecksart
// Analysen
public static TriangleType checkTriangle(float a, float b, float c) {
if(checkIfNotValid(a,b,c)) return TriangleType.NONE;
if(checkIfEquilateral(a,b,c)) return TriangleType.EQUILATERAL;
if(checkIfIsosceles(a,b,c)) return TriangleType.ISOSCELES;
if(checkIfNormal(a,b,c)) return TriangleType.NORMAL;
return TriangleType.NONE;
}

// Analyse kein Dreieck
private static boolean checkIfNotValid(float a, float b, float c){
if (a + b <= c || a + c <= b || b + c <= a) return true;
return false;
}

// Analyse normales Dreieck
private static boolean checkIfNormal(float a, float b, float c){
if (a != b && b != c && a != c) return true;
return false;
}

// Analyse gleichschenkliges Dreieck
private static boolean checkIfIsosceles(float a, float b, float c){
if (a == b || a == c || b == c) return true;
return false;
}

// Analyse gleichseitiges Dreieck
private static boolean checkIfEquilateral(float a, float b, float c){
if (a == b && b == c) return true;
return false;
}
}

+ 45
- 2
test/TriangleCheckerTest.java View File

@@ -2,7 +2,7 @@ import org.junit.Test;
import static org.junit.Assert.*;

public class TriangleCheckerTest {
@Test
public void testValidTriangle() {

@@ -16,7 +16,50 @@ public class TriangleCheckerTest {

// Assert
assertEquals(TriangleChecker.TriangleType.NORMAL, type);
}

@Test
public void testIfNotValidTriangle_SumOfTwoSidesEqualsThird() {

// Arrange
float a = 10;
float b = 20;
float c = 30;

// Act
TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a, b, c);

// Assert
assertEquals(TriangleChecker.TriangleType.NONE, type);
}

}
@Test
public void testEquilateralTriangle() {

// Arrange
float a = 1;
float b = 1;
float c = 1;

// Act
TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a, b, c);

// Assert
assertEquals(TriangleChecker.TriangleType.EQUILATERAL, type);
}

@Test
public void testIsoscelesTriangleIfAEqualsB() {

// Arrange
float a = 10;
float b = 10;
float c = 5;

// Act
TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a, b, c);

// Assert
assertEquals(TriangleChecker.TriangleType.ISOSCELES, type);
}
}

Loading…
Cancel
Save