Browse Source

Zahlenfelder Vers1. Objektorientiert

main
moritz 3 weeks ago
parent
commit
ae803b20ea
2 changed files with 81 additions and 3 deletions
  1. 16
    3
      src/praktikum02/TriangleChecker.java
  2. 65
    0
      test/praktikum02/TriangleCheckerTest.java

+ 16
- 3
src/praktikum02/TriangleChecker.java View File

System.out.println("Kein Dreieck"); System.out.println("Kein Dreieck");
break; break;
case NORMAL: case NORMAL:
System.out.println("Dreieck");
System.out.println("normales Dreieck");
break; break;
case ISOSCELES: case ISOSCELES:
System.out.println("Gleichschenkliges Dreieck"); System.out.println("Gleichschenkliges Dreieck");


// 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 && 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; return TriangleType.NORMAL;
} }



}
}

+ 65
- 0
test/praktikum02/TriangleCheckerTest.java View File

void checkTriangleNormal() { void checkTriangleNormal() {
assertEquals(TriangleChecker.TriangleType.NORMAL,TriangleChecker.checkTriangle( 10 ,5,6) ); 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…
Cancel
Save