new program

This commit is contained in:
Johannes Weichelt 2021-12-24 12:01:01 +01:00
parent 0fa3277440
commit 8fd57fc6c6
2 changed files with 75 additions and 13 deletions

View File

@ -47,6 +47,19 @@ public class TriangleChecker {
// 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) {
return TriangleType.NORMAL;
if (checkTriangleBasePossibility(a, b, c)) {
if (a == b && a == c) return TriangleType.EQUILATERAL;
if (a == b || a == c || b == c) return TriangleType.ISOSCELES;
return TriangleType.NORMAL;
}
return TriangleType.NONE;
} }
public static boolean checkTriangleBasePossibility(float a, float b, float c) {
if (a <= 0 || b <= 0 || c <= 0) return false;
return a + b > c && a + c > b && b + c > a;
}
} }

View File

@ -4,12 +4,12 @@ import static org.junit.Assert.*;
public class TriangleCheckerTest { public class TriangleCheckerTest {
@Test @Test
public void testValidTriangle() { public void testIsTriangle() {
// Arrange // Arrange
float a = 7; float a = 3;
float b = 3; float b = 2;
float c = 1; float c = 4;
// Act // Act
TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a, b, c); TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a, b, c);
@ -17,6 +17,55 @@ public class TriangleCheckerTest {
// Assert // Assert
assertEquals(TriangleChecker.TriangleType.NORMAL, type); assertEquals(TriangleChecker.TriangleType.NORMAL, type);
// Arrange
a = -2;
b = 5;
c = 2;
// Act
type = TriangleChecker.checkTriangle(a, b, c);
// Assert
assertEquals(TriangleChecker.TriangleType.NONE, type);
// Arrange
a = 5;
b = 5;
c = 10;
// Act
type = TriangleChecker.checkTriangle(a, b, c);
// Assert
assertEquals(TriangleChecker.TriangleType.NONE, type);
}
@Test
public void testIsoTriangle(){
// Arrange
float a = 6;
float b = 6;
float c = 3;
// Act
TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a, b, c);
// Assert
assertEquals(TriangleChecker.TriangleType.ISOSCELES, type);
}
@Test
public void testEqualTriangle(){
// Arrange
float a = 5;
float b = 5;
float c = 5;
// Act
TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a, b, c);
// Assert
assertEquals(TriangleChecker.TriangleType.EQUILATERAL, type);
} }
} }