Browse Source

modified case detections in the main program, created tests

master
Phil 2 years ago
parent
commit
10edd0c2b4
2 changed files with 56 additions and 11 deletions
  1. 16
    1
      src/TriangleChecker.java
  2. 40
    10
      test/TriangleCheckerTest.java

+ 16
- 1
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(checkTrianglePossible(a, b, c)) {
if (a == b && a == c) {
return TriangleType.EQUILATERAL;
}
if (a == b || a == c || b == c) {
return TriangleType.ISOSCELES;
}
return TriangleType.NORMAL;
}
return TriangleType.NONE; return TriangleType.NONE;
} }




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

+ 40
- 10
test/TriangleCheckerTest.java View File

import static org.junit.Assert.*; import static org.junit.Assert.*;


public class TriangleCheckerTest { public class TriangleCheckerTest {

// Arrange
float a = 2;
float b = 3;
float c = 4;
float d = - a;

TriangleChecker.TriangleType none = TriangleChecker.TriangleType.NONE;
TriangleChecker.TriangleType normal = TriangleChecker.TriangleType.NORMAL;
TriangleChecker.TriangleType isosceles = TriangleChecker.TriangleType.ISOSCELES; // Gleichschenklig
TriangleChecker.TriangleType equilateral = TriangleChecker.TriangleType.EQUILATERAL; // Gleichseitig


@Test @Test
public void testValidTriangle() { public void testValidTriangle() {


// Arrange
float a = 2;
float b = 3;
float c = 4;
assertTrue(TriangleChecker.checkTrianglePossible(a,b,c));
assertFalse(TriangleChecker.checkTrianglePossible(0,0,0));
assertFalse(TriangleChecker.checkTrianglePossible(0,b,c));
assertFalse(TriangleChecker.checkTrianglePossible(a,0,c));
assertFalse(TriangleChecker.checkTrianglePossible(a,b,0));

//combination of falses
assertFalse(TriangleChecker.checkTrianglePossible(d,c,c));
assertFalse(TriangleChecker.checkTrianglePossible(0,0,c));
assertFalse(TriangleChecker.checkTrianglePossible(d,d,d));
assertFalse(TriangleChecker.checkTrianglePossible(a,b,0));
}


// Act
TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a, b, c);
@Test
public void testTriangleType(){


// Assert
assertEquals(TriangleChecker.TriangleType.NORMAL, type);
assertEquals(none, TriangleChecker.checkTriangle(a, b, 400));


}
assertEquals(normal, TriangleChecker.checkTriangle(a, b, c));


assertEquals(isosceles, TriangleChecker.checkTriangle(a, b, b));
assertEquals(isosceles, TriangleChecker.checkTriangle(a, a, c/3));
assertEquals(isosceles, TriangleChecker.checkTriangle(c, b, c));
assertNotEquals(isosceles, TriangleChecker.checkTriangle(a, b, c));
assertNotEquals(isosceles, TriangleChecker.checkTriangle(a, a, a));

assertNotEquals(equilateral, TriangleChecker.checkTriangle(b, a, a));
assertEquals(equilateral, TriangleChecker.checkTriangle(a, a, a));
assertNotEquals(equilateral, TriangleChecker.checkTriangle(a, b, a));
assertNotEquals(equilateral, TriangleChecker.checkTriangle(a, a, b));
}
} }

Loading…
Cancel
Save