Last active
August 29, 2015 14:02
-
-
Save ilya-murzinov/d70d7c5655f5760dc1d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Before; | |
import org.junit.Test; | |
import static org.junit.Assert.assertNotEquals; | |
import static org.junit.Assert.assertTrue; | |
/** | |
* @author Murzinov Ilya, [email protected] | |
* Date 12.06.14 | |
*/ | |
public class RtriangleProviderTests { | |
/** | |
* Let sideA be length of the side between (X1, Y1) and (X2, Y2). | |
* Let sideB be length of the side between (X2, Y2) and (X3, Y3). | |
* Let sideC be length of the side between (X1, Y1) and (X3, Y3). | |
*/ | |
private Rtriangle rtriangle = RtriangleProvider.getRtriangle(); | |
private double sideA; | |
private double sideB; | |
private double sideC; | |
@Before | |
public void init() { | |
sideA = Math.sqrt(Math.pow(rtriangle.getApexX1() - rtriangle.getApexX2(), 2) | |
+ Math.pow(rtriangle.getApexY1() - rtriangle.getApexY2(), 2)); | |
sideB = Math.sqrt(Math.pow(rtriangle.getApexX2() - rtriangle.getApexX3(), 2) | |
+ Math.pow(rtriangle.getApexY2() - rtriangle.getApexY3(), 2)); | |
sideC = Math.sqrt(Math.pow(rtriangle.getApexX1() - rtriangle.getApexX3(), 2) | |
+ Math.pow(rtriangle.getApexY1() - rtriangle.getApexY3(), 2)); | |
} | |
@Test | |
public void sideAShouldNotBeZeroTest() { | |
assertNotEquals(0d, sideA); | |
} | |
@Test | |
public void sideBShouldNotBeZeroTest() { | |
assertNotEquals(0d, sideB); | |
} | |
@Test | |
public void sideCShouldNotBeZeroTest() { | |
assertNotEquals(0d, sideC); | |
} | |
@Test | |
public void triangleInequalityShouldHold() { | |
assertTrue("Triangle inequality should hold", sideA + sideB > sideC | |
|| sideA + sideC > sideB | |
|| sideC + sideB > sideA); | |
} | |
@Test | |
public void pythagoreanTheoremShouldHold() { | |
assertTrue("Pythagorean theorem should hold", | |
Math.pow(sideA, 2) + Math.pow(sideB, 2) == Math.pow(sideC, 2) | |
|| Math.pow(sideA, 2) + Math.pow(sideC, 2) == Math.pow(sideB, 2) | |
|| Math.pow(sideB, 2) + Math.pow(sideC, 2) == Math.pow(sideA, 2)); | |
} | |
} | |
interface Rtriangle { | |
int getApexX1(); | |
int getApexY1(); | |
int getApexX2(); | |
int getApexY2(); | |
int getApexX3(); | |
int getApexY3(); | |
} | |
/** | |
* RtriangleProvider stub. | |
*/ | |
final class RtriangleProvider { | |
public static Rtriangle getRtriangle() { | |
return new Rtriangle() { | |
@Override | |
public int getApexX1() { | |
return 0; | |
} | |
@Override | |
public int getApexY1() { | |
return 0; | |
} | |
@Override | |
public int getApexX2() { | |
return 0; | |
} | |
@Override | |
public int getApexY2() { | |
return 0; | |
} | |
@Override | |
public int getApexX3() { | |
return 0; | |
} | |
@Override | |
public int getApexY3() { | |
return 0; | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment