Skip to content

Instantly share code, notes, and snippets.

@tmshv
Last active March 22, 2016 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmshv/a69ece8190a50498d40f to your computer and use it in GitHub Desktop.
Save tmshv/a69ece8190a50498d40f to your computer and use it in GitHub Desktop.
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