Browse Source

Assignment TriangleChecker

master
Tatjana Kim 3 years ago
parent
commit
84734ec53e
2 changed files with 25 additions and 3 deletions
  1. 12
    0
      src/TriangleChecker.java
  2. 13
    3
      test/TriangleCheckerTest.java

+ 12
- 0
src/TriangleChecker.java View File

@@ -47,8 +47,20 @@ public class TriangleChecker {

// Analyse der Dreiecksart
public static TriangleType checkTriangle(float a, float b, float c) {
if (checkTriangleType(a,b,c) ){
if(a==b && a==c){return TriangleType.EQUILATERAL;}
if(a==b||b==c||a==c){return TriangleType.ISOSCELES;}

return TriangleType.NORMAL;
}
return TriangleType.NONE;
}


public static boolean checkTriangleType(float a, float b, float c) {
if (a <= 0 || b <= 0 || c <= 0) {
return false;
}
return (a + b > c && b + c > a && a + c > b);
}
}

+ 13
- 3
test/TriangleCheckerTest.java View File

@@ -10,12 +10,22 @@ public class TriangleCheckerTest {
float a = 2;
float b = 3;
float c = 4;
float d = 12;
float e = 32;
float f = 7;
float h = 11;
float g = 41;
float i = 4;

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

// Assert
assertEquals(TriangleChecker.TriangleType.NORMAL, type);
assertTrue(TriangleChecker.checkTriangleType(a, b, c));
assertFalse(TriangleChecker.checkTriangleType(a, d, c));
assertTrue(TriangleChecker.checkTriangleType(e, d, e));
assertFalse(TriangleChecker.checkTriangleType(a, f, h));
assertFalse(TriangleChecker.checkTriangleType(i, c, d));
assertFalse(TriangleChecker.checkTriangleType(g, i, d));


}


Loading…
Cancel
Save