Browse Source

Commit TriangleChecker Assignment

master
Lena Kauffmann 3 years ago
parent
commit
f2b2b85866
2 changed files with 50 additions and 1 deletions
  1. 8
    1
      src/TriangleChecker.java
  2. 42
    0
      test/TriangleCheckerTest.java

+ 8
- 1
src/TriangleChecker.java View File

@@ -47,7 +47,14 @@ public class TriangleChecker {

// Analyse der Dreiecksart
public static TriangleType checkTriangle(float a, float b, float c) {
return TriangleType.NONE;
if(a==b && b==c) {return TriangleType.EQUILATERAL;}
else if (a+b>c && b+c>a && a+c>b) {
if (a==b && a!=c || b==c && b!=a || a==c && a!=b ){return TriangleType.ISOSCELES;}
else {return TriangleType.NORMAL;}
}
else {return TriangleType.NONE;}


}



+ 42
- 0
test/TriangleCheckerTest.java View File

@@ -19,4 +19,46 @@ public class TriangleCheckerTest {

}

@Test
public void testEquilateralTriangle(){
// Arrange
float a = 3;
float b = 3;
float c = 3;

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

// Assert
assertEquals(TriangleChecker.TriangleType.EQUILATERAL, type);
}

@Test
public void testNoTriangle(){
// Arrange
float a = 1;
float b = 100;
float c = 1;

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

// Assert
assertEquals(TriangleChecker.TriangleType.NONE, type);
}

@Test
public void testIsocelesTriangle(){
// Arrange
float a = 3;
float b = 3;
float c = 4;

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

// Assert
assertEquals(TriangleChecker.TriangleType.ISOSCELES, type);
}

}

Loading…
Cancel
Save