Last active
March 22, 2016 14:33
-
-
Save tmshv/a69ece8190a50498d40f to your computer and use it in GitHub Desktop.
This file contains 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 static org.junit.Assert.assertEquals; | |
import static org.junit.Assert.assertTrue; | |
import org.junit.Before; | |
import org.junit.Test; | |
import java.util.Arrays; | |
public class Testtriangle { | |
Rtriangle triangle; | |
@Before | |
public void setUp() { | |
triangle = RtriangleProvider.getRtriangle(); | |
} | |
@Test | |
public void test() { | |
int x1 = triangle.getApexX1(); | |
int y1 = triangle.getApexY1(); | |
int x2 = triangle.getApexX2(); | |
int y2 = triangle.getApexY2(); | |
int x3 = triangle.getApexX3(); | |
int y3 = triangle.getApexY3(); | |
double[] lengths = { | |
distQuad(x1, y1, x2, y2), | |
distQuad(x2, y2, x3, y3), | |
distQuad(x1, y1, x3, y3) | |
}; | |
Arrays.sort(lengths); | |
assertEquals(lengths[0] + lengths[1], lengths[2], 0); | |
assertTrue(oneLine(x1, y1, x2, y2, x3, y3) != 0); | |
} | |
private double distQuad(int x1, int y1, int x2, int y2){ | |
return (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2); | |
} | |
private double oneLine(int x1, int y1, int x2, int y2, int x3, int y3){ | |
return (x1 - x3)*(y2 - y3) - (x2 - x3)*(y1 - y3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment