Advertisement
Guest User

Point2Tester.java

a guest
Apr 24th, 2015
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.49 KB | None | 0 0
  1. public class Point2Tester {
  2.     public static void main(String[] args)
  3.     {        
  4.         System.out.println("--- Testing Point2 API ---");
  5.         System.out.println("Test Passed means that you passed.");
  6.         System.out.println("modified by Ohad Rubin");
  7.        
  8.         System.out.println("\nTesting constructor\n\tPoint2 p1 = new Point2(3, 4);");
  9.         Point2 p1 = new Point2(3, 4);
  10.         System.out.println("Passed.");
  11.        
  12.         System.out.println("\nTesting getX() and getY()");
  13.         System.out.println("\tp1.getX() = " + p1.getX() + ", p1.getY() = " + p1.getY());
  14.         System.out.println((p1.getX()==3&&p1.getY()==4)?"Passed.":"Failed. Output should be 3,4");
  15.        
  16.         System.out.println("\nTesting toString()");
  17.         System.out.println("\tp1.toString() = " + p1.toString());
  18.         System.out.println((p1.toString().equals("(3,4)"))?"Passed.":"Failed. Output should be (3,4)");
  19.        
  20.         System.out.println("\nTesting copy constructor\n\tPoint2 p2 = new Point2(p1);");
  21.         Point2 p2 = new Point2(p1);
  22.         System.out.println("\tp2.toString() = " + p2.toString());
  23.         System.out.println((p2.toString().equals("(3,4)"))?"Passed.":"Failed. Output should be (3,4)");
  24.        
  25.         System.out.println("\nTesting equals()");
  26.         System.out.println("\tp1.equals(p2) = " + p1.equals(p2));
  27.         System.out.println((p1.equals(p2) == true)?"Passed.":"Failed. Output should be true");
  28.        
  29.         System.out.println("\nTesting setX() and setY()");
  30.         p2.setX(5);
  31.         p2.setY(5);
  32.         System.out.println("\tp2.getX() = " + p2.getX() + ", p2.getY() = " + p2.getY());
  33.         System.out.println((p2.getX()==5&&p2.getY()==5)?"Passed.":"Failed. Output should be 5,5");
  34.         System.out.println("\tp1.equals(p2) = " + p1.equals(p2));
  35.         System.out.println((false==p1.equals(p2))?"Passed.":"Failed. Output should be false");
  36.        
  37.         System.out.println("\nTesting isAbove() and isUnder()");
  38.         System.out.println("\tp1.isAbove(p2) = " + p1.isAbove(p2) + ", p2.isAbove(p1) = " + p2.isAbove(p1));
  39.         System.out.println("\tp1.isUnder(p2) = " + p1.isUnder(p2) + ", p2.isUnder(p1) = " + p2.isUnder(p1));
  40.         System.out.println("Output should be f t t f");
  41.        
  42.         System.out.println("\nTesting isLeft() and isRight()");
  43.         System.out.println("\tp1.isLeft(p2) = " + p1.isLeft(p2) + ", p2.isLeft(p1) = " + p2.isLeft(p1));
  44.         System.out.println("\tp1.isRight(p2) = " + p1.isRight(p2) + ", p2.isRight(p1) = " + p2.isRight(p1));        
  45.         System.out.println("Output should be t f f t");
  46.        
  47.         System.out.println("\nTesting distance()");
  48.         System.out.println("\tp1.distance(p2) = " + p1.distance(p2) + ", p2.distance(p1) = " + p2.distance(p1));
  49.         System.out.println((p1.distance(p2)==2.23606797749979)?"Passed.":"Failed. Output should be 2.23606797749979");
  50.        
  51.         System.out.println("\nTesting move()\n\tPoint2 p1.move(-2, 7);");
  52.         p1.move(-2, 7);
  53.         System.out.println("\tp1 = " + p1.toString());
  54.        System.out.println((p1.toString().equals("(1,11)"))?"Passed.":"Failed. Output should be (1,11)");
  55.  
  56.  
  57.                System.out.println("\nTesting move()\n\tPoint2 p1.move(-2, 7);");
  58.        System.out.println("\nTesting more stuff");
  59.  
  60.        Point2 p3 = new Point2(3, 0);
  61.  
  62.  
  63.        System.out.println("\tp3 = " + p3.toString());
  64.  
  65.         System.out.println((p3.toString().equals("(3,0)"))?"Passed.":"Failed. Output should be (3,0)");
  66.  
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement