Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Point2Tester {
- public static void main(String[] args)
- {
- System.out.println("--- Testing Point2 API ---");
- System.out.println("Test Passed means that you passed.");
- System.out.println("modified by Ohad Rubin");
- System.out.println("\nTesting constructor\n\tPoint2 p1 = new Point2(3, 4);");
- Point2 p1 = new Point2(3, 4);
- System.out.println("Passed.");
- System.out.println("\nTesting getX() and getY()");
- System.out.println("\tp1.getX() = " + p1.getX() + ", p1.getY() = " + p1.getY());
- System.out.println((p1.getX()==3&&p1.getY()==4)?"Passed.":"Failed. Output should be 3,4");
- System.out.println("\nTesting toString()");
- System.out.println("\tp1.toString() = " + p1.toString());
- System.out.println((p1.toString().equals("(3,4)"))?"Passed.":"Failed. Output should be (3,4)");
- System.out.println("\nTesting copy constructor\n\tPoint2 p2 = new Point2(p1);");
- Point2 p2 = new Point2(p1);
- System.out.println("\tp2.toString() = " + p2.toString());
- System.out.println((p2.toString().equals("(3,4)"))?"Passed.":"Failed. Output should be (3,4)");
- System.out.println("\nTesting equals()");
- System.out.println("\tp1.equals(p2) = " + p1.equals(p2));
- System.out.println((p1.equals(p2) == true)?"Passed.":"Failed. Output should be true");
- System.out.println("\nTesting setX() and setY()");
- p2.setX(5);
- p2.setY(5);
- System.out.println("\tp2.getX() = " + p2.getX() + ", p2.getY() = " + p2.getY());
- System.out.println((p2.getX()==5&&p2.getY()==5)?"Passed.":"Failed. Output should be 5,5");
- System.out.println("\tp1.equals(p2) = " + p1.equals(p2));
- System.out.println((false==p1.equals(p2))?"Passed.":"Failed. Output should be false");
- System.out.println("\nTesting isAbove() and isUnder()");
- System.out.println("\tp1.isAbove(p2) = " + p1.isAbove(p2) + ", p2.isAbove(p1) = " + p2.isAbove(p1));
- System.out.println("\tp1.isUnder(p2) = " + p1.isUnder(p2) + ", p2.isUnder(p1) = " + p2.isUnder(p1));
- System.out.println("Output should be f t t f");
- System.out.println("\nTesting isLeft() and isRight()");
- System.out.println("\tp1.isLeft(p2) = " + p1.isLeft(p2) + ", p2.isLeft(p1) = " + p2.isLeft(p1));
- System.out.println("\tp1.isRight(p2) = " + p1.isRight(p2) + ", p2.isRight(p1) = " + p2.isRight(p1));
- System.out.println("Output should be t f f t");
- System.out.println("\nTesting distance()");
- System.out.println("\tp1.distance(p2) = " + p1.distance(p2) + ", p2.distance(p1) = " + p2.distance(p1));
- System.out.println((p1.distance(p2)==2.23606797749979)?"Passed.":"Failed. Output should be 2.23606797749979");
- System.out.println("\nTesting move()\n\tPoint2 p1.move(-2, 7);");
- p1.move(-2, 7);
- System.out.println("\tp1 = " + p1.toString());
- System.out.println((p1.toString().equals("(1,11)"))?"Passed.":"Failed. Output should be (1,11)");
- System.out.println("\nTesting move()\n\tPoint2 p1.move(-2, 7);");
- System.out.println("\nTesting more stuff");
- Point2 p3 = new Point2(3, 0);
- System.out.println("\tp3 = " + p3.toString());
- System.out.println((p3.toString().equals("(3,0)"))?"Passed.":"Failed. Output should be (3,0)");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement