Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a unit test for class Point using the following test cases. *I will try to upvote instantly* public class Point { private int x;

image text in transcribedCreate a unit test for class Point using the following test cases.

*I will try to upvote instantly*

image text in transcribed

public class Point { private int x; private int y; /** * Initializes a newly created Point object with x and y coordinates set to 0. */ public Point() { } /** * Initializes a newly created Point object with the given values. * * @param x the x coordinate of this point * @param y the y coordinate of this point */ public Point(int x, int y) { } /** * Initializes a newly created Point object with the values from the input Point object. * * @param other a Point object used to initialize this Point object */ public Point(Point other) { } /** * Returns the x coordinate of this Point object. * * @return the x coordinate of this object. */ public int getX() { } /** * Returns the y coordinate of this Point object. * * @return the y coordinate of this object. */ public int getY() { } /** * Returns a String object that represents this Point as, * for example, (5,3) if x is 5 and y is 3. * * @return a string representation of this Point's value. */ public String toString() { // TO DO return null; } /** * Compares this object to the other object. The result is true if and * only if the argument is not null and is a Point object that contains the * same values as this Point object. * * @param other the object to compare with. * * @return true if the objects are the same; false otherwise. */ public boolean equals(Object other) { if (other == null || !(other instanceof Point)) return false; Point p = (Point) other; // Write code for the rest of this method below return false; } }
An Example of Unit Test public class Point Test { @Test public void test Constructori() { Point p = new Point (4,5); assertEquals(" (4,5)", p.toString()); @Test public void testGetterx() { Point p = new Point (4,5); assertEquals (4.0, p.getX(), 0.00001); Test public void test Equals() { Point p = new Point(4,5); assert False (p.equals (null)); @Test public void testEquals() Point pl = new Point (4,5); Point p2 = new Point (4,5); assert True (pl.equals (p2)); @Test public void testEquals() { Point pl = new Point (4,5); Point p2 = new Point (4,3); assert False (pl.equals(p2)); Test cases for Constructors Test Cases Point p = new Point(); 1 Point p = new Point(5,10); Expected Result getX() should return 0 getY() should return 0 getX() should return 5 getY() should return 10 q.getX() should return 5 q.getY() should return 10 Point p = new Point(5,10); Point q = new Point(p); Test cases for toString() Expected Result "(0,0)" Test Cases Point p = new Point() p.toString() Point p = new Point(5,10) p.toString() Point p = new Point(3,12); Point q = new Point(p); q.toString() "(5,10)" "(3,12)" Test cases for equals() Expected Result false 1 true Test Cases Point p = new Point(5,10) p.equals(null) Point p = new Point(5,10) Point q = new Point(5,10) p.equals(a) Point p = new Point(5,10) Point q = new Point(10,5) p.equals(a) false

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Define the term "Leasing"

Answered: 1 week ago

Question

What do you mean by Dividend ?

Answered: 1 week ago

Question

What is database?

Answered: 1 week ago

Question

What are Mergers ?

Answered: 1 week ago