import static org.junit.Assert.*; import java.util.Random; import org.junit.Test; public class RectangleTest { @Test public void testGetWidth() { Random random = new Random(System.currentTimeMillis()); final int NUMBER = 1000; for (int n = 0; n < NUMBER; n++) { int width = Math.abs(random.nextInt()); int height = Math.abs(random.nextInt()); Rectangle rectangle = new Rectangle(width, height); assertEquals(width, rectangle.getWidth()); } int height = Math.abs(random.nextInt()); Rectangle rectangle = new Rectangle(0, height); assertEquals(0, rectangle.getWidth()); height = Math.abs(random.nextInt()); rectangle = new Rectangle(Integer.MAX_VALUE, height); assertEquals(Integer.MAX_VALUE, rectangle.getWidth()); } @Test public void testGetHeight() { Random random = new Random(System.currentTimeMillis()); final int NUMBER = 1000; for (int n = 0; n < NUMBER; n++) { int width = Math.abs(random.nextInt()); int height = Math.abs(random.nextInt()); Rectangle rectangle = new Rectangle(width, height); assertEquals(height, rectangle.getHeight()); } int width = Math.abs(random.nextInt()); Rectangle rectangle = new Rectangle(width, 0); assertEquals(0, rectangle.getHeight()); width = Math.abs(random.nextInt()); rectangle = new Rectangle(width, Integer.MAX_VALUE); assertEquals(Integer.MAX_VALUE, rectangle.getHeight()); } @Test public void testSetWidth() { Random random = new Random(System.currentTimeMillis()); final int NUMBER = 1000; for (int n = 0; n < NUMBER; n++) { int width = Math.abs(random.nextInt()); int height = Math.abs(random.nextInt()); Rectangle rectangle = new Rectangle(width, height); int newWidth = Math.abs(random.nextInt()); rectangle.setWidth(newWidth); assertEquals(newWidth, rectangle.getWidth()); } int width = Math.abs(random.nextInt()); int height = Math.abs(random.nextInt()); Rectangle rectangle = new Rectangle(width, height); rectangle.setWidth(0); assertEquals(0, rectangle.getWidth()); width = Math.abs(random.nextInt()); height = Math.abs(random.nextInt()); rectangle = new Rectangle(width, height); rectangle.setWidth(Integer.MAX_VALUE); assertEquals(Integer.MAX_VALUE, rectangle.getWidth()); } // test other methods similarly }