2
0

~ Fehler behoben

Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
Johannes Theiner 2020-04-23 13:32:16 +02:00
parent b03b293ffe
commit 3418b5446d
5 changed files with 104 additions and 98 deletions

View File

@ -11,14 +11,16 @@ public class TriangleChecker {
if (a <= 0 || b <= 0 || c <= 0)
return TriangleType.NO_TRIANGLE;
if (a == b && a == c)
return TriangleType.EQUILATERAL_TRIANGLE;
if ((long)a + (long)b > (long)c && (long)a + (long)c > (long)b && (long)b + (long)c > (long)a) {
if (a == b && a == c)
return TriangleType.EQUILATERAL_TRIANGLE;
if (a == b || a == c || b == c)
return TriangleType.ISOSCELESS_TRIANGLE;
if (a == b || a == c || b == c)
return TriangleType.ISOSCELESS_TRIANGLE;
if (a + b > c && a + c > b && b + c > a)
return TriangleType.SCALENE_TRIANGLE;
}
return TriangleType.NO_TRIANGLE;
}

View File

@ -1,51 +0,0 @@
import de.hsel.sqs.TriangleChecker;
import de.hsel.sqs.TriangleType;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
public class TriangleTest {
@Test
public void noTriangle() {
TriangleChecker tc = new TriangleChecker();
assertEquals(TriangleChecker.checkTriangle(8, 2, 3), TriangleType.NO_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(2, 8, 3), TriangleType.NO_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(2, 3, 8), TriangleType.NO_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(-1, 5, -3), TriangleType.NO_TRIANGLE);
}
@Test
public void equilateralTriangle() {
TriangleChecker tc = new TriangleChecker();
assertEquals(TriangleChecker.checkTriangle(5, 5, 5), TriangleType.EQUILATERAL_TRIANGLE);
}
@Test
public void isocelessTriangle() {
TriangleChecker tc = new TriangleChecker();
assertEquals(TriangleChecker.checkTriangle(7, 7, 2), TriangleType.ISOSCELESS_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(6, 10, 10), TriangleType.ISOSCELESS_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(4, 3, 4), TriangleType.ISOSCELESS_TRIANGLE);
}
@Test
public void scaleneTriangle() {
TriangleChecker tc = new TriangleChecker();
assertEquals(TriangleChecker.checkTriangle(5, 7, 9), TriangleType.SCALENE_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(3, 5, 4), TriangleType.SCALENE_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(7, 15, 10), TriangleType.SCALENE_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(9, 5, 7), TriangleType.SCALENE_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(4, 3, 5), TriangleType.SCALENE_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(10, 7, 15), TriangleType.SCALENE_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(7, 9, 5), TriangleType.SCALENE_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(5, 4, 3), TriangleType.SCALENE_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(15, 10, 7), TriangleType.SCALENE_TRIANGLE);
}
}

View File

@ -1,42 +0,0 @@
import de.hsel.sqs.TriangleChecker;
import de.hsel.sqs.TriangleType;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
public class WhiteboxTest {
@Test
public void instruction() {
TriangleChecker tc = new TriangleChecker();
assertEquals(TriangleChecker.checkTriangle(-1, 2, 5), TriangleType.NO_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(5, 5, 5), TriangleType.EQUILATERAL_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(3, 3, 4), TriangleType.ISOSCELESS_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(7, 15, 10), TriangleType.SCALENE_TRIANGLE);
}
@Test
public void branch() {
TriangleChecker tc = new TriangleChecker();
assertEquals(TriangleChecker.checkTriangle(-1, 5, 3), TriangleType.NO_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(5, 5, 5), TriangleType.EQUILATERAL_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(2, 2, 5), TriangleType.ISOSCELESS_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(7, 15, 10), TriangleType.SCALENE_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(7, 18, 10), TriangleType.NO_TRIANGLE);
}
@Test
public void defined() {
TriangleChecker tc = new TriangleChecker();
assertEquals(TriangleChecker.checkTriangle(-1, 5, 3), TriangleType.NO_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(5, 5, 5), TriangleType.EQUILATERAL_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(2, 2, 5), TriangleType.ISOSCELESS_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(7, 15, 10), TriangleType.SCALENE_TRIANGLE);
assertEquals(TriangleChecker.checkTriangle(8, 2, 3), TriangleType.NO_TRIANGLE);
}
}

View File

@ -0,0 +1,55 @@
package de.hsel.sqs;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
public class TriangleTest {
@Test
public void noTriangle() {
TriangleChecker tc = new TriangleChecker();
assertEquals(TriangleType.NO_TRIANGLE, TriangleChecker.checkTriangle(8, 2, 3));
assertEquals(TriangleType.NO_TRIANGLE, TriangleChecker.checkTriangle(2, 8, 3));
assertEquals(TriangleType.NO_TRIANGLE, TriangleChecker.checkTriangle(2, 3, 8));
assertEquals(TriangleType.NO_TRIANGLE, TriangleChecker.checkTriangle(-1, 5, -3));
assertEquals(TriangleType.NO_TRIANGLE, TriangleChecker.checkTriangle(1, 1, 5));
}
@Test
public void equilateralTriangle() {
TriangleChecker tc = new TriangleChecker();
assertEquals(TriangleType.EQUILATERAL_TRIANGLE, TriangleChecker.checkTriangle(5, 5, 5));
assertEquals(TriangleType.EQUILATERAL_TRIANGLE, TriangleChecker.checkTriangle(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE));
}
@Test
public void isocelessTriangle() {
TriangleChecker tc = new TriangleChecker();
assertEquals(TriangleType.ISOSCELESS_TRIANGLE, TriangleChecker.checkTriangle(7, 7, 2));
assertEquals(TriangleType.ISOSCELESS_TRIANGLE, TriangleChecker.checkTriangle(6, 10, 10));
assertEquals(TriangleType.ISOSCELESS_TRIANGLE, TriangleChecker.checkTriangle(4, 3, 4));
}
@Test
public void scaleneTriangle() {
TriangleChecker tc = new TriangleChecker();
assertEquals(TriangleType.SCALENE_TRIANGLE, TriangleChecker.checkTriangle(5, 7, 9));
assertEquals(TriangleType.SCALENE_TRIANGLE, TriangleChecker.checkTriangle(3, 5, 4));
assertEquals(TriangleType.SCALENE_TRIANGLE, TriangleChecker.checkTriangle(7, 15, 10));
assertEquals(TriangleType.SCALENE_TRIANGLE, TriangleChecker.checkTriangle(9, 5, 7));
assertEquals(TriangleType.SCALENE_TRIANGLE, TriangleChecker.checkTriangle(4, 3, 5));
assertEquals(TriangleType.SCALENE_TRIANGLE, TriangleChecker.checkTriangle(10, 7, 15));
assertEquals(TriangleType.SCALENE_TRIANGLE, TriangleChecker.checkTriangle(7, 9, 5));
assertEquals(TriangleType.SCALENE_TRIANGLE, TriangleChecker.checkTriangle(5, 4, 3));
assertEquals(TriangleType.SCALENE_TRIANGLE, TriangleChecker.checkTriangle(15, 10, 7));
assertEquals(TriangleType.SCALENE_TRIANGLE, TriangleChecker.checkTriangle(Integer.MAX_VALUE, Integer.MAX_VALUE-1, Integer.MAX_VALUE-2));
}
}

View File

@ -0,0 +1,42 @@
package de.hsel.sqs;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
public class WhiteboxTest {
@Test
public void instruction() {
TriangleChecker tc = new TriangleChecker();
assertEquals(TriangleType.NO_TRIANGLE, TriangleChecker.checkTriangle(-1, 2, 5));
assertEquals(TriangleType.EQUILATERAL_TRIANGLE, TriangleChecker.checkTriangle(5, 5, 5));
assertEquals(TriangleType.ISOSCELESS_TRIANGLE, TriangleChecker.checkTriangle(3, 3, 4));
assertEquals(TriangleType.SCALENE_TRIANGLE, TriangleChecker.checkTriangle(7, 15, 10));
}
@Test
public void branch() {
TriangleChecker tc = new TriangleChecker();
assertEquals(TriangleType.NO_TRIANGLE, TriangleChecker.checkTriangle(-1, 5, 3));
assertEquals(TriangleType.EQUILATERAL_TRIANGLE, TriangleChecker.checkTriangle(5, 5, 5));
assertEquals(TriangleType.ISOSCELESS_TRIANGLE, TriangleChecker.checkTriangle(2, 2, 3));
assertEquals(TriangleType.SCALENE_TRIANGLE, TriangleChecker.checkTriangle(7, 15, 10));
assertEquals(TriangleType.NO_TRIANGLE, TriangleChecker.checkTriangle(7, 18, 10));
}
@Test
public void defined() {
TriangleChecker tc = new TriangleChecker();
assertEquals(TriangleType.NO_TRIANGLE, TriangleChecker.checkTriangle(-1, 5, 3));
assertEquals(TriangleType.EQUILATERAL_TRIANGLE, TriangleChecker.checkTriangle(5, 5, 5));
assertEquals(TriangleType.ISOSCELESS_TRIANGLE, TriangleChecker.checkTriangle(2, 2, 3));
assertEquals(TriangleType.SCALENE_TRIANGLE, TriangleChecker.checkTriangle(7, 15, 10));
assertEquals(TriangleType.NO_TRIANGLE, TriangleChecker.checkTriangle(8, 2, 3));
}
}