Zahlenfelder Vers1. Objektorientiert
This commit is contained in:
parent
6b11baff87
commit
ae803b20ea
@ -36,7 +36,7 @@ public class TriangleChecker {
|
||||
System.out.println("Kein Dreieck");
|
||||
break;
|
||||
case NORMAL:
|
||||
System.out.println("Dreieck");
|
||||
System.out.println("normales Dreieck");
|
||||
break;
|
||||
case ISOSCELES:
|
||||
System.out.println("Gleichschenkliges Dreieck");
|
||||
@ -49,8 +49,21 @@ public class TriangleChecker {
|
||||
|
||||
// Analyse der Dreiecksart
|
||||
public static TriangleType checkTriangle(float a, float b, float c) {
|
||||
|
||||
if (a == b && b == c && a == c){return TriangleType.EQUILATERAL;}
|
||||
|
||||
if (a == b || b == c || a == c){return TriangleType.ISOSCELES;}
|
||||
|
||||
if (a <= 0 || b <= 0 || c <= 0){return TriangleType.NONE;}
|
||||
|
||||
if (a + b < c){return TriangleType.NONE;}
|
||||
|
||||
if (a + c < b){return TriangleType.NONE;}
|
||||
|
||||
if (b + c < a){return TriangleType.NONE;}
|
||||
|
||||
|
||||
return TriangleType.NORMAL;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -10,4 +10,69 @@ class TriangleCheckerTest {
|
||||
void checkTriangleNormal() {
|
||||
assertEquals(TriangleChecker.TriangleType.NORMAL,TriangleChecker.checkTriangle( 10 ,5,6) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkTriangleISOSCELES_AB() {
|
||||
assertEquals(TriangleChecker.TriangleType.ISOSCELES,TriangleChecker.checkTriangle( 10 ,10,5) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkTriangleISOSCELES_BC() {
|
||||
assertEquals(TriangleChecker.TriangleType.ISOSCELES,TriangleChecker.checkTriangle( 10 ,5,5) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkTriangleISOSCELES_AC() {
|
||||
assertEquals(TriangleChecker.TriangleType.ISOSCELES,TriangleChecker.checkTriangle( 10 ,5,10) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkTriangle_EQUILATERAL() {
|
||||
assertEquals(TriangleChecker.TriangleType.EQUILATERAL,TriangleChecker.checkTriangle( 10 ,10,10) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkTriangleNONE_A() {
|
||||
assertEquals(TriangleChecker.TriangleType.NONE,TriangleChecker.checkTriangle( 0 ,10,5) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkTriangleNONE_B() {
|
||||
assertEquals(TriangleChecker.TriangleType.NONE,TriangleChecker.checkTriangle( 10 ,0,5) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkTriangleNONE_C() {
|
||||
assertEquals(TriangleChecker.TriangleType.NONE,TriangleChecker.checkTriangle( 10 ,5,0) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkTriangleNONE_minusA() {
|
||||
assertEquals(TriangleChecker.TriangleType.NONE,TriangleChecker.checkTriangle( -2 ,10,5) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkTriangleNONE_minusB() {
|
||||
assertEquals(TriangleChecker.TriangleType.NONE,TriangleChecker.checkTriangle( 10 ,-2,5) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkTriangleNONE_minusC() {
|
||||
assertEquals(TriangleChecker.TriangleType.NONE,TriangleChecker.checkTriangle( 10 ,5,-2) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkTriangleNONE_AB_C() {
|
||||
assertEquals(TriangleChecker.TriangleType.NONE,TriangleChecker.checkTriangle( 10 ,2,13) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkTriangleNONE_AC_B() {
|
||||
assertEquals(TriangleChecker.TriangleType.NONE,TriangleChecker.checkTriangle( 10 ,13,2) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkTriangleNONE_BC_A() {
|
||||
assertEquals(TriangleChecker.TriangleType.NONE,TriangleChecker.checkTriangle( 13 ,10,2) );
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user