Browse Source

new program

master
Johannes Weichelt 2 years ago
parent
commit
8fd57fc6c6
2 changed files with 75 additions and 13 deletions
  1. 20
    7
      src/TriangleChecker.java
  2. 55
    6
      test/TriangleCheckerTest.java

+ 20
- 7
src/TriangleChecker.java View File

import java.util.Scanner; import java.util.Scanner;


public class TriangleChecker { public class TriangleChecker {
public enum TriangleType { public enum TriangleType {
NONE,
NONE,
NORMAL, NORMAL,
ISOSCELES, // Gleichschenklig ISOSCELES, // Gleichschenklig
EQUILATERAL // Gleichseitig EQUILATERAL // Gleichseitig
switch (type) { switch (type) {
case NONE: case NONE:
System.out.println("Kein Dreieck"); System.out.println("Kein Dreieck");
break;
break;
case NORMAL: case NORMAL:
System.out.println("Dreieck"); System.out.println("Dreieck");
break;
break;
case ISOSCELES: case ISOSCELES:
System.out.println("Gleichschenkliges Dreieck"); System.out.println("Gleichschenkliges Dreieck");
break;
break;
case EQUILATERAL: case EQUILATERAL:
System.out.println("Gleichseitiges Dreieck"); System.out.println("Gleichseitiges Dreieck");
break;
break;
} }
} }


// 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) {
return TriangleType.NORMAL;

if (checkTriangleBasePossibility(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;
} }

public static boolean checkTriangleBasePossibility(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;
}


} }

+ 55
- 6
test/TriangleCheckerTest.java View File

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


public class TriangleCheckerTest { public class TriangleCheckerTest {
@Test @Test
public void testValidTriangle() {
public void testIsTriangle() {


// Arrange // Arrange
float a = 7;
float b = 3;
float c = 1;
float a = 3;
float b = 2;
float c = 4;


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


// Arrange
a = -2;
b = 5;
c = 2;

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

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

// Arrange
a = 5;
b = 5;
c = 10;

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

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

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

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

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

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

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

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


}
}

Loading…
Cancel
Save