Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.junit.Test;
- import java.math.BigInteger;
- import static java.math.BigInteger.ZERO;
- import static java.math.BigInteger.valueOf;
- import static org.junit.Assert.*;
- public class Testtriangle {
- @Test
- public void test() {
- for (int i = 0; i < 100; i++) {
- testTriangle(RtriangleProvider.getRtriangle());
- }
- }
- private BigInteger getSquaredLength(int x1, int y1, int x2, int y2) {
- return valueOf((long)x1 - x2).pow(2).add(valueOf((long)y1 - y2).pow(2));
- }
- public void testTriangle(Rtriangle triangle) {
- BigInteger a2 = getSquaredLength(triangle.getApexX1(), triangle.getApexY1(),triangle.getApexX2(), triangle.getApexY2());
- assertNotEquals("a equals 0!", ZERO, a2);
- BigInteger b2 = getSquaredLength(triangle.getApexX1(), triangle.getApexY1(),triangle.getApexX3(), triangle.getApexY3());
- assertNotEquals("b equals 0!", ZERO, b2);
- BigInteger c2 = getSquaredLength(triangle.getApexX2(), triangle.getApexY2(), triangle.getApexX3(), triangle.getApexY3());
- assertNotEquals("c equals 0!", ZERO, c2);
- if (c2.compareTo(a2) > 0 && c2.compareTo(b2) > 0) {
- assertEquals("a^2 + b^2 != c^2", a2.add(b2), c2);
- } else if (b2.compareTo(a2) > 0 && b2.compareTo(c2) > 0) {
- assertEquals("a^2 + c^2 != b^2", a2.add(c2), b2);
- } else {
- assertEquals("b^2 + c^2 != a^2", c2.add(b2), a2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement