Browse Source

Gleichschenklige Dreiecke werden erkannt

master
Mikko Winkler 2 years ago
parent
commit
6244920b66
2 changed files with 18 additions and 4 deletions
  1. 4
    2
      src/TriangleChecker.java
  2. 14
    2
      test/TriangleCheckerTest.java

+ 4
- 2
src/TriangleChecker.java View File

public static TriangleType checkTriangle(float a, float b, float c) { public static TriangleType checkTriangle(float a, float b, float c) {


if( (a+b>c) && (c+b>a) && (a+c>b)) { if( (a+b>c) && (c+b>a) && (a+c>b)) {
if(a==b && b==c && a==c) return TriangleType.ISOSCELES;
if(a==b || b==c|| a==c) {
if (a == b && b == c && a == c) return TriangleType.EQUILATERAL;
return TriangleType.ISOSCELES;
}
return TriangleType.NORMAL; return TriangleType.NORMAL;
} }



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



+ 14
- 2
test/TriangleCheckerTest.java View File

} }


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


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


@Test
public void testEqualTriangle(){
// 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);
}


} }

Loading…
Cancel
Save