Question: JUnit - Complete all To Do so that it would pass all tests _______________________________________________________ Rectangle.java public class Rectangle { // constants - there's only one

JUnit - Complete all To Do so that it would pass all tests

_______________________________________________________

Rectangle.java

public class Rectangle

{

// constants - there's only one needed.

//TODO: Fix

// static variables

//TODO: Fix

// instance variables

//TODO: Fix

/**

* Default ctor. Constructs a rectangle with width 1 and

* heigght 1.

*/

public Rectangle()

{

//TODO: Fix

}

/**

* Ctor with params to construct any size rectangle.

*

* @param newWidth

* @param newHeight

*/

public Rectangle(double newWidth, double newHeight)

{

//TODO: Fix

}

/**

* Gets the area of a rectangle.

*

* @return

*/

public double getArea()

{

//TODO: Fix

return 42.0;

}

/**

* Gets the perimeter of a rectangle.

*

* @return

*/

public double getPerimeter()

{

//TODO: Fix

return 42.0;

}

/**

* Scales the rectangle by a given factor only if the number is

* 0 or positive. Otherwise leaves the dimensions unchanged.

* @param factor

*/

public void scale(double factor)

{

//TODO: Fix

}

/**

* Returns the dimensions of a rectangle in the format 3 X 5

* @return

*/

public String getBasicDimensions()

{

return "42";

}

/**

* Returns the dimensions of a rectangle along with the

* unique ID number of that rectangle.

* The ID of the first rectangle created ever is 1.

* "Rectangle #34 is 7 X 4"

* This means that this is the 34th rectangle ever created.

* @return

*/

public String getFancyDimensions()

{

//TODO: Fix

return "42";

}

/**

* returns the number of times all rectangles have

* been scaled successfully.

* @return

*/

public static int getScaleCount()

{

//TODO: Fix

return 42;

}

}

/**

___________________________________________________________________________

JU17VTest.java * Do not just test one method at a time, or static * variables will be offset. Make sure to always * run all tests at once. */ import static org.junit.Assert.*;

import java.lang.reflect.Field; import org.junit.Test; import org.junit.Before; import org.junit.BeforeClass; //keep the tests from scrambling otherwise would drive students insane. import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters;

@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class JU17VTest {

@Test public void test01TestGetRectangleSentence1() { Rectangle box = new Rectangle(); //#1 assertEquals("1.0 X 1.0", box.getBasicDimensions()); }

@Test public void test01TestGetRectangleSentence2() { Rectangle box = new Rectangle(2, 5.51); //#2 Rectangle square = new Rectangle(5, 5); //#3 Rectangle table = new Rectangle(3, 8); //#4 Rectangle roof = new Rectangle(9, 4); //#5 assertEquals("9.0 X 4.0", roof.getBasicDimensions()); }

@Test public void test02TestGetArea1() { Rectangle box = new Rectangle(3, 4); //#6 assertEquals("12.0", box.getArea() + ""); }

@Test public void test02TestGetArea2() { Rectangle box = new Rectangle(7, 5); //#7 assertEquals("35.0", box.getArea() + ""); }

@Test public void test03TestPerimeter1() { Rectangle box = new Rectangle(7, 4); //#8 assertEquals("22.0", box.getPerimeter() + ""); }

@Test public void test03TestPerimeter2() { Rectangle box = new Rectangle(3, 2); //#9 assertEquals("10.0", box.getPerimeter() + ""); } @Test public void test04FancyDimensions1() { Rectangle box = new Rectangle(); //#10 assertEquals("Rectangle #10 is 1.0 X 1.0", box.getFancyDimensions()); } @Test public void test04FancyDimensions2() { Rectangle box = new Rectangle(66, 42); //#10 assertEquals("Rectangle #11 is 66.0 X 42.0", box.getFancyDimensions()); } @Test public void test04FancyDimensions3() { Rectangle box = new Rectangle(); //#11 Rectangle door = new Rectangle(3, 4); //#12 Rectangle fridge = new Rectangle(3, 4); //#13 assertEquals("Rectangle #14 is 3.0 X 4.0", fridge.getFancyDimensions()); }

@Test public void test05TestScale1() { Rectangle box = new Rectangle(5, 1); box.scale(2.0); assertEquals("10.0 X 2.0", box.getBasicDimensions()); } @Test public void test05TestScale2() { Rectangle box = new Rectangle(7, 4); box.scale(0.5); assertEquals("3.5 X 2.0", box.getBasicDimensions()); } @Test public void test05TestScale3() { Rectangle box = new Rectangle(7, 5); box.scale(-2.0); assertEquals("7.0 X 5.0", box.getBasicDimensions()); } @Test public void test05TestScale4() { Rectangle box = new Rectangle(8, 8); box.scale(-0.0001); assertEquals("8.0 X 8.0", box.getBasicDimensions()); } @Test public void test06SuccessfulScaleCount1() { Rectangle door = new Rectangle(8, 15); assertEquals("2", Rectangle.getScaleCount() + ""); } @Test public void test06SuccessfulScaleCount2() { Rectangle door = new Rectangle(8, 15); door.scale(3); door.scale(10); door.scale(20); door.scale(-2.0); //will not scale negative. assertEquals("5", Rectangle.getScaleCount() + ""); } @Test public void test06SuccessfulScaleCount3() { Rectangle door = new Rectangle(8, 15); door.scale(-3); door.scale(100); door.scale(-12); door.scale(20); door.scale(-2.0); assertEquals("7", Rectangle.getScaleCount() + ""); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!