2015-05-31 11:55:18 +03:00
|
|
|
package com.iluwatar.doubledispatch;
|
2015-05-08 22:57:14 +03:00
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
2015-12-11 20:14:52 +01:00
|
|
|
import static junit.framework.TestCase.assertEquals;
|
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
2015-05-31 11:55:18 +03:00
|
|
|
|
2015-05-09 19:26:35 +03:00
|
|
|
/**
|
|
|
|
* Unit test for Rectangle
|
|
|
|
*/
|
2015-05-08 22:57:14 +03:00
|
|
|
public class RectangleTest {
|
|
|
|
|
2015-12-11 20:14:52 +01:00
|
|
|
/**
|
|
|
|
* Test if the values passed through the constructor matches the values fetched from the getters
|
|
|
|
*/
|
2015-11-01 21:29:13 -05:00
|
|
|
@Test
|
2015-12-11 20:14:52 +01:00
|
|
|
public void testConstructor() {
|
|
|
|
final Rectangle rectangle = new Rectangle(1, 2, 3, 4);
|
|
|
|
assertEquals(1, rectangle.getLeft());
|
|
|
|
assertEquals(2, rectangle.getTop());
|
|
|
|
assertEquals(3, rectangle.getRight());
|
|
|
|
assertEquals(4, rectangle.getBottom());
|
2015-11-01 21:29:13 -05:00
|
|
|
}
|
2015-12-11 20:14:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if the values passed through the constructor matches the values in the {@link
|
|
|
|
* #toString()}
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testToString() throws Exception {
|
|
|
|
final Rectangle rectangle = new Rectangle(1, 2, 3, 4);
|
|
|
|
assertEquals("[1,2,3,4]", rectangle.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if the {@link Rectangle} class can detect if it intersects with another rectangle.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testIntersection() {
|
|
|
|
assertTrue(new Rectangle(0, 0, 1, 1).intersectsWith(new Rectangle(0, 0, 1, 1)));
|
|
|
|
assertTrue(new Rectangle(0, 0, 1, 1).intersectsWith(new Rectangle(-1, -5, 7, 8)));
|
|
|
|
assertFalse(new Rectangle(0, 0, 1, 1).intersectsWith(new Rectangle(2, 2, 3, 3)));
|
|
|
|
assertFalse(new Rectangle(0, 0, 1, 1).intersectsWith(new Rectangle(-2, -2, -1, -1)));
|
|
|
|
}
|
|
|
|
|
2015-05-08 22:57:14 +03:00
|
|
|
}
|