Browse Source

Assignment TriangleChecker

master
Tatjana Kim 2 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



// 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 (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; 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

float a = 2; float a = 2;
float b = 3; float b = 3;
float c = 4; 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 // 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