From ae803b20ea05a856f08c204e80575f1445ad7641 Mon Sep 17 00:00:00 2001 From: moritz Date: Tue, 29 Oct 2024 15:55:42 +0100 Subject: [PATCH] Zahlenfelder Vers1. Objektorientiert --- src/praktikum02/TriangleChecker.java | 19 +++++-- test/praktikum02/TriangleCheckerTest.java | 65 +++++++++++++++++++++++ 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/src/praktikum02/TriangleChecker.java b/src/praktikum02/TriangleChecker.java index 114481a..20943ea 100644 --- a/src/praktikum02/TriangleChecker.java +++ b/src/praktikum02/TriangleChecker.java @@ -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; } - -} \ No newline at end of file + } \ No newline at end of file diff --git a/test/praktikum02/TriangleCheckerTest.java b/test/praktikum02/TriangleCheckerTest.java index 585868c..854e33d 100644 --- a/test/praktikum02/TriangleCheckerTest.java +++ b/test/praktikum02/TriangleCheckerTest.java @@ -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) ); + } } \ No newline at end of file