Add proper unit tests for double-dispatch pattern
This commit is contained in:
committed by
Jeroen Meulemeester
parent
2edc1898b1
commit
c837ffe234
@@ -1,22 +1,47 @@
|
||||
package com.iluwatar.doubledispatch;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.iluwatar.doubledispatch.Rectangle;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
*
|
||||
* Unit test for Rectangle
|
||||
*
|
||||
*/
|
||||
public class RectangleTest {
|
||||
|
||||
/**
|
||||
* Test if the values passed through the constructor matches the values fetched from the getters
|
||||
*/
|
||||
@Test
|
||||
public void test() {
|
||||
Assert.assertTrue(new Rectangle(0, 0, 1, 1).intersectsWith(new Rectangle(0, 0, 1, 1)));
|
||||
Assert.assertTrue(new Rectangle(0, 0, 1, 1).intersectsWith(new Rectangle(-1, -5, 7, 8)));
|
||||
Assert.assertFalse(new Rectangle(0, 0, 1, 1).intersectsWith(new Rectangle(2, 2, 3, 3)));
|
||||
Assert.assertFalse(new Rectangle(0, 0, 1, 1).intersectsWith(new Rectangle(-2, -2, -1, -1)));
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user