Question: NEED HELP ASAP JAVA TEST HELP Prepare a JUnit test for a LineSegment ADT. The LineSegment represents the portion of a 2-dimensional line that lies
NEED HELP ASAP JAVA TEST HELP Prepare a JUnit test for a LineSegment ADT. The LineSegment represents the portion of a 2-dimensional line that lies between two endpoints. It supports operations such as finding the corresponding x (or y) value of a point given its y (or x) coordinate, determining whether two line segments intersect (and, if so, where), and finding the distance of an arbitrary point from the closest point on the line segment. For more details, refer to the API documentation for the Magazine class in the assignment directory.
LineSegment.java
package edu.odu.cs.cs350; import java.awt.geom.Point2D; /** * A line segment in the 2-D plane. * * This is a stub that we would typically create for a class still to be * written, serving as a placeholder while the unit tests are being designed. * The function bodies are empty, except for just enough code * (typically "return" statements) to allow the code to compile without * error. * * @author zeil * */ class LineSegment implements Cloneable { /** * Create a line segment bounded by two points. * @param p1 one endpoint * @param p2 another endpoint * * @precondition: !p1.equals(p2) */ public LineSegment (Point2D.Double p1, Point2D.Double p2) { // TODO } /** * Get the first endpoint defining a line segment. * * @return one endpoint of the line segment */ public Point2D.Double getP1() { // TODO return new Point2D.Double(1.0, 0.0); } /** * Change the first endpoint defining a line segment. * * @param p1 new endpoint of the line segment */ public void setP1(Point2D.Double p1) { // TODO } /** * Get the second endpoint defining a line segment. * * @return an endpoint of the line segment */ public Point2D.Double getP2() { // TODO return new Point2D.Double(0.0, 1.0); } /** * Change the second endpoint defining a line segment. * * @param p2 new endpoint of the line segment */ public void setP2(Point2D.Double p2) { // TODO } /** * Determine if two line segments intersect. * @param ls a line segment * @return true iff the segments intersect at a common point between their * respective pairs of endpoints. */ public boolean intersects (LineSegment ls) { // TODO return true; } /** * Create a string describing this line segment, identifying the two * endpoints. * * @return string representation of this line. */ public String toString() { // TODO return ""; } /** * Solve this segment for y. * @param x An x value. * @return The value of y such that (x,y) is a point on this segment. If there * is no unique such y value (because the line is vertical), * return NaN or if any such point (x,y) would lie outside the * two endpoints; */ double y(double x) { // TODO return 0.0; } /** * Solve this segment for x. * @param y An y value. * @return The value of x such that (x,y) is a point on this segment. If there * is no unique such x value (because the line is horizontal), * return NaN. */ double x(double y) { // TODO return 0.0; } /** * Return the intersection of two segments * @param ls a line segment * @return intersection point between two segments * @throws ArithmeticException if the lines are parallel or * any intersection would lie outside the bounds of one * or both segments. */ Point2D.Double intersection (LineSegment ls) throws ArithmeticException { // TODO return new Point2D.Double(0.0, 0.0); } /** * Compute the distance of a point from this line segment. * If the orthogonal projection of this point onto the line passing * through this segment lies outside the endpoints, return the distance to * the closer endpoint. * * @param p A point * @return distance of that point from this line */ double distance (Point2D.Double p) { // TODO return 1.0; } public boolean equals(Object obj) { // TODO return true; } /** * Create a deep copy of this segment. */ public Object clone() { // TODO return this; } }
TestLineSegment.java
package edu.odu.cs.cs350; import static org.junit.jupiter.api.Assertions.*; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.awt.geom.Point2D; public class TestLineSegment { // TODO Any data members that you want to share among different tests /** * @throws java.lang.Exception */ @BeforeEach public void setUp() throws Exception { //TODO Any initialization of those shared data members } @Test public void testSomething() { //TODO first of your test cases } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
