mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-16 08:58:49 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -33,10 +33,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Testing methods in Bubble class.
|
||||
*/
|
||||
|
||||
/** Testing methods in Bubble class. */
|
||||
class BubbleTest {
|
||||
|
||||
@Test
|
||||
@@ -45,7 +42,7 @@ class BubbleTest {
|
||||
var initialX = b.coordinateX;
|
||||
var initialY = b.coordinateY;
|
||||
b.move();
|
||||
//change in x and y < |2|
|
||||
// change in x and y < |2|
|
||||
assertTrue(b.coordinateX - initialX < 2 && b.coordinateX - initialX > -2);
|
||||
assertTrue(b.coordinateY - initialY < 2 && b.coordinateY - initialY > -2);
|
||||
}
|
||||
@@ -55,7 +52,7 @@ class BubbleTest {
|
||||
var b1 = new Bubble(0, 0, 1, 2);
|
||||
var b2 = new Bubble(1, 1, 2, 1);
|
||||
var b3 = new Bubble(10, 10, 3, 1);
|
||||
//b1 touches b2 but not b3
|
||||
// b1 touches b2 but not b3
|
||||
assertTrue(b1.touches(b2));
|
||||
assertFalse(b1.touches(b3));
|
||||
}
|
||||
@@ -68,7 +65,7 @@ class BubbleTest {
|
||||
bubbles.put(1, b1);
|
||||
bubbles.put(2, b2);
|
||||
b1.pop(bubbles);
|
||||
//after popping, bubble no longer in hashMap containing all bubbles
|
||||
// after popping, bubble no longer in hashMap containing all bubbles
|
||||
assertNull(bubbles.get(1));
|
||||
assertNotNull(bubbles.get(2));
|
||||
}
|
||||
@@ -86,7 +83,7 @@ class BubbleTest {
|
||||
bubblesToCheck.add(b2);
|
||||
bubblesToCheck.add(b3);
|
||||
b1.handleCollision(bubblesToCheck, bubbles);
|
||||
//b1 touches b2 and not b3, so b1, b2 will be popped
|
||||
// b1 touches b2 and not b3, so b1, b2 will be popped
|
||||
assertNull(bubbles.get(1));
|
||||
assertNull(bubbles.get(2));
|
||||
assertNotNull(bubbles.get(3));
|
||||
|
||||
@@ -33,10 +33,7 @@ import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Testing QuadTree class.
|
||||
*/
|
||||
|
||||
/** Testing QuadTree class. */
|
||||
class QuadTreeTest {
|
||||
|
||||
@Test
|
||||
@@ -47,22 +44,21 @@ class QuadTreeTest {
|
||||
var p = new Bubble(rand.nextInt(300), rand.nextInt(300), i, rand.nextInt(2) + 1);
|
||||
points.add(p);
|
||||
}
|
||||
var field = new Rect(150, 150, 300, 300); //size of field
|
||||
var queryRange = new Rect(70, 130, 100, 100); //result = all points lying in this rectangle
|
||||
//points found in the query range using quadtree and normal method is same
|
||||
var field = new Rect(150, 150, 300, 300); // size of field
|
||||
var queryRange = new Rect(70, 130, 100, 100); // result = all points lying in this rectangle
|
||||
// points found in the query range using quadtree and normal method is same
|
||||
var points1 = QuadTreeTest.quadTreeTest(points, field, queryRange);
|
||||
var points2 = QuadTreeTest.verify(points, queryRange);
|
||||
assertEquals(points1, points2);
|
||||
}
|
||||
|
||||
static Hashtable<Integer, Point> quadTreeTest(Collection<Point> points, Rect field, Rect queryRange) {
|
||||
//creating quadtree and inserting all points
|
||||
static Hashtable<Integer, Point> quadTreeTest(
|
||||
Collection<Point> points, Rect field, Rect queryRange) {
|
||||
// creating quadtree and inserting all points
|
||||
var qTree = new QuadTree(queryRange, 4);
|
||||
points.forEach(qTree::insert);
|
||||
|
||||
return qTree
|
||||
.query(field, new ArrayList<>())
|
||||
.stream()
|
||||
return qTree.query(field, new ArrayList<>()).stream()
|
||||
.collect(Collectors.toMap(p -> p.id, p -> p, (a, b) -> b, Hashtable::new));
|
||||
}
|
||||
|
||||
|
||||
@@ -29,10 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Testing Rect class.
|
||||
*/
|
||||
|
||||
/** Testing Rect class. */
|
||||
class RectTest {
|
||||
|
||||
@Test
|
||||
@@ -40,7 +37,7 @@ class RectTest {
|
||||
var r = new Rect(10, 10, 20, 20);
|
||||
var b1 = new Bubble(2, 2, 1, 1);
|
||||
var b2 = new Bubble(30, 30, 2, 1);
|
||||
//r contains b1 and not b2
|
||||
// r contains b1 and not b2
|
||||
assertTrue(r.contains(b1));
|
||||
assertFalse(r.contains(b2));
|
||||
}
|
||||
@@ -50,7 +47,7 @@ class RectTest {
|
||||
var r1 = new Rect(10, 10, 20, 20);
|
||||
var r2 = new Rect(15, 15, 20, 20);
|
||||
var r3 = new Rect(50, 50, 20, 20);
|
||||
//r1 intersects r2 and not r3
|
||||
// r1 intersects r2 and not r3
|
||||
assertTrue(r1.intersects(r2));
|
||||
assertFalse(r1.intersects(r3));
|
||||
}
|
||||
|
||||
+2
-5
@@ -30,10 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import java.util.HashMap;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Testing SpatialPartition_Bubbles class.
|
||||
*/
|
||||
|
||||
/** Testing SpatialPartition_Bubbles class. */
|
||||
class SpatialPartitionBubblesTest {
|
||||
|
||||
@Test
|
||||
@@ -55,7 +52,7 @@ class SpatialPartitionBubblesTest {
|
||||
qt.insert(b4);
|
||||
var sp = new SpatialPartitionBubbles(bubbles, qt);
|
||||
sp.handleCollisionsUsingQt(b1);
|
||||
//b1 touches b3 and b4 but not b2 - so b1,b3,b4 get popped
|
||||
// b1 touches b3 and b4 but not b2 - so b1,b3,b4 get popped
|
||||
assertNull(bubbles.get(1));
|
||||
assertNotNull(bubbles.get(2));
|
||||
assertNull(bubbles.get(3));
|
||||
|
||||
Reference in New Issue
Block a user