Archived
0

move to test util check paths

This commit is contained in:
iMoHax
2015-07-15 11:24:33 +03:00
parent 9d645a2aec
commit 40e4d2b377
2 changed files with 36 additions and 33 deletions

View File

@@ -2,9 +2,13 @@ package ru.trader;
import org.junit.Assert; import org.junit.Assert;
import ru.trader.analysis.graph.Edge;
import ru.trader.analysis.graph.PPath;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
public class TestUtil { public class TestUtil {
@@ -113,4 +117,18 @@ public class TestUtil {
checkContains(collection, true, items); checkContains(collection, true, items);
} }
public static <T> void assertPaths(Collection<List<Edge<T>>> paths, PPath... points) {
assertPaths(false, paths, points);
}
public static <T> void assertPaths(boolean saveOrder, Collection<List<Edge<T>>> paths, PPath... points){
Collection<PPath> actual = new ArrayList<>(paths.size());
paths.forEach(p -> actual.add(PPath.of(p)));
if (saveOrder) {
TestUtil.assertCollectionEquals(actual, points);
} else {
TestUtil.assertCollectionContainAll(actual, points);
}
}
} }

View File

@@ -11,7 +11,6 @@ import ru.trader.core.Profile;
import ru.trader.core.Ship; import ru.trader.core.Ship;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
public class CrawlerTest extends Assert { public class CrawlerTest extends Assert {
@@ -60,20 +59,6 @@ public class CrawlerTest extends Assert {
} }
} }
private void assertPaths(List<List<Edge<Point>>> paths, PPath... points) {
assertPaths(false, paths, points);
}
private void assertPaths(boolean saveOrder, List<List<Edge<Point>>> paths, PPath... points){
Collection<PPath> actual = new ArrayList<>(paths.size());
paths.forEach(p -> actual.add(PPath.of(p)));
if (saveOrder) {
TestUtil.assertCollectionEquals(actual, points);
} else {
TestUtil.assertCollectionContainAll(actual, points);
}
}
@Test @Test
public void testGetPaths() throws Exception { public void testGetPaths() throws Exception {
LOG.info("Start get paths test"); LOG.info("Start get paths test");
@@ -90,11 +75,11 @@ public class CrawlerTest extends Assert {
SimpleCollector<Point> paths = new SimpleCollector<>(); SimpleCollector<Point> paths = new SimpleCollector<>();
Crawler<Point> crawler = new CCrawler<>(graph, paths::add); Crawler<Point> crawler = new CCrawler<>(graph, paths::add);
crawler.findMin(x4, 10); crawler.findMin(x4, 10);
assertPaths(paths.get(), PPath.of(x5, x4)); TestUtil.assertPaths(paths.get(), PPath.of(x5, x4));
paths.clear(); paths.clear();
crawler.findMin(x6, 10); crawler.findMin(x6, 10);
assertPaths(paths.get(), PPath.of(x5, x6)); TestUtil.assertPaths(paths.get(), PPath.of(x5, x6));
paths.clear(); paths.clear();
crawler.findMin(x7, 10); crawler.findMin(x7, 10);
@@ -120,20 +105,20 @@ public class CrawlerTest extends Assert {
Crawler<Point> crawler = new CCrawler<>(graph, paths::add); Crawler<Point> crawler = new CCrawler<>(graph, paths::add);
crawler.findMin(x8, 10); crawler.findMin(x8, 10);
assertPaths(paths.get(), PPath.of(x5, x6, x7, x8)); TestUtil.assertPaths(paths.get(), PPath.of(x5, x6, x7, x8));
paths.clear(); paths.clear();
crawler.findMin(x7, 10); crawler.findMin(x7, 10);
assertPaths(paths.get(), PPath.of(x5, x6, x7), PPath.of(x5, x4, x6, x7), PPath.of(x5, x3, x6, x7)); TestUtil.assertPaths(paths.get(), PPath.of(x5, x6, x7), PPath.of(x5, x4, x6, x7), PPath.of(x5, x3, x6, x7));
paths.clear(); paths.clear();
crawler.findMin(x7); crawler.findMin(x7);
assertEquals(1, paths.get().size()); assertEquals(1, paths.get().size());
assertPaths(paths.get(), PPath.of(x5, x6, x7)); TestUtil.assertPaths(paths.get(), PPath.of(x5, x6, x7));
paths.clear(); paths.clear();
crawler.findMin(x4, 20); crawler.findMin(x4, 20);
assertPaths(true, paths.get(), PPath.of(x5, x4), PPath.of(x5, x3, x4), PPath.of(x5, x6, x4), TestUtil.assertPaths(true, paths.get(), PPath.of(x5, x4), PPath.of(x5, x3, x4), PPath.of(x5, x6, x4),
PPath.of(x5, x6, x5, x4), PPath.of(x5, x4, x5, x4), PPath.of(x5, x4, x3, x4), PPath.of(x5, x6, x5, x4), PPath.of(x5, x4, x5, x4), PPath.of(x5, x4, x3, x4),
PPath.of(x5, x4, x6, x4), PPath.of(x5, x6, x3, x4), PPath.of(x5, x4, x6, x4), PPath.of(x5, x6, x3, x4),
PPath.of(x5, x3, x5, x4), PPath.of(x5, x4, x2, x4), PPath.of(x5, x3, x5, x4), PPath.of(x5, x4, x2, x4),
@@ -147,7 +132,7 @@ public class CrawlerTest extends Assert {
paths.clear(); paths.clear();
crawler.findMin(x5, 20); crawler.findMin(x5, 20);
assertPaths(paths.get(), PPath.of(x5, x4, x5), PPath.of(x5, x4, x6, x5), PPath.of(x5, x4, x3, x5), TestUtil.assertPaths(paths.get(), PPath.of(x5, x4, x5), PPath.of(x5, x4, x6, x5), PPath.of(x5, x4, x3, x5),
PPath.of(x5, x6, x5), PPath.of(x5, x6, x4, x5), PPath.of(x5, x6, x3, x5), PPath.of(x5, x3, x5), PPath.of(x5, x6, x5), PPath.of(x5, x6, x4, x5), PPath.of(x5, x6, x3, x5), PPath.of(x5, x3, x5),
PPath.of(x5, x3, x4, x5), PPath.of(x5, x3, x6, x5)); PPath.of(x5, x3, x4, x5), PPath.of(x5, x3, x6, x5));
paths.clear(); paths.clear();
@@ -158,7 +143,7 @@ public class CrawlerTest extends Assert {
crawler.findFast(x7, 10); crawler.findFast(x7, 10);
assertEdges(paths.get(0), x5, x6, x7); assertEdges(paths.get(0), x5, x6, x7);
assertPaths(paths.get(), PPath.of(x5, x6, x7), PPath.of(x5, x4, x6, x7), PPath.of(x5, x3, x6, x7)); TestUtil.assertPaths(paths.get(), PPath.of(x5, x6, x7), PPath.of(x5, x4, x6, x7), PPath.of(x5, x3, x6, x7));
paths.clear(); paths.clear();
crawler.findFast(x4); crawler.findFast(x4);
@@ -188,11 +173,11 @@ public class CrawlerTest extends Assert {
paths.clear(); paths.clear();
crawler.findMin(x2, 10); crawler.findMin(x2, 10);
assertPaths(paths.get(), PPath.of(x5, x4, x3, x2), PPath.of(x5, x3, x2)); TestUtil.assertPaths(paths.get(), PPath.of(x5, x4, x3, x2), PPath.of(x5, x3, x2));
paths.clear(); paths.clear();
crawler.findMin(x6, 10); crawler.findMin(x6, 10);
assertPaths(paths.get(), PPath.of(x5, x6), PPath.of(x5, x4, x6), TestUtil.assertPaths(paths.get(), PPath.of(x5, x6), PPath.of(x5, x4, x6),
PPath.of(x5, x4, x5, x6), PPath.of(x5, x6, x5, x6), PPath.of(x5, x4, x5, x6), PPath.of(x5, x6, x5, x6),
PPath.of(x5, x3, x4, x6), PPath.of(x5, x3, x5, x6), PPath.of(x5, x3, x4, x6), PPath.of(x5, x3, x5, x6),
PPath.of(x5, x6, x4, x6)); PPath.of(x5, x6, x4, x6));
@@ -203,7 +188,7 @@ public class CrawlerTest extends Assert {
paths.clear(); paths.clear();
crawler.findFast(x2); crawler.findFast(x2);
assertPaths(paths.get(), PPath.of(x5, x3, x2)); TestUtil.assertPaths(paths.get(), PPath.of(x5, x3, x2));
paths.clear(); paths.clear();
} }
@@ -231,7 +216,7 @@ public class CrawlerTest extends Assert {
paths.clear(); paths.clear();
crawler.findMin(x2, 20); crawler.findMin(x2, 20);
assertPaths(paths.get(), PPath.of(x5, x3, x4, x2), PPath.of(x5, x3, x2), TestUtil.assertPaths(paths.get(), PPath.of(x5, x3, x4, x2), PPath.of(x5, x3, x2),
PPath.of(x5, x4, x3, x2), PPath.of(x5, x4, x2), PPath.of(x5, x3, x5, x4, x2), PPath.of(x5, x4, x3, x2), PPath.of(x5, x4, x2), PPath.of(x5, x3, x5, x4, x2),
PPath.of(x5, x6, x4, x2), PPath.of(x5, x6, x4, x3, x2), PPath.of(x5, x4, x3, x4, x2), PPath.of(x5, x6, x4, x2), PPath.of(x5, x6, x4, x3, x2), PPath.of(x5, x4, x3, x4, x2),
PPath.of(x5, x4, x5, x4, x2), PPath.of(x5, x6, x5, x4, x2), PPath.of(x5, x3, x4, x3, x2), PPath.of(x5, x4, x5, x4, x2), PPath.of(x5, x6, x5, x4, x2), PPath.of(x5, x3, x4, x3, x2),
@@ -239,7 +224,7 @@ public class CrawlerTest extends Assert {
paths.clear(); paths.clear();
crawler.findMin(x6, 30); crawler.findMin(x6, 30);
assertPaths(paths.get(), PPath.of(x5, x6), PPath.of(x5, x4, x6), TestUtil.assertPaths(paths.get(), PPath.of(x5, x6), PPath.of(x5, x4, x6),
PPath.of(x5, x3, x4, x6), PPath.of(x5, x3, x6), PPath.of(x5, x4, x3, x6), PPath.of(x5, x3, x4, x6), PPath.of(x5, x3, x6), PPath.of(x5, x4, x3, x6),
PPath.of(x5, x3, x4, x3, x6), PPath.of(x5, x3, x4, x5, x6), PPath.of(x5, x3, x5, x6), PPath.of(x5, x3, x4, x3, x6), PPath.of(x5, x3, x4, x5, x6), PPath.of(x5, x3, x5, x6),
PPath.of(x5, x3, x5, x4, x6), PPath.of(x5, x4, x3, x4, x6), PPath.of(x5, x4, x3, x5, x6), PPath.of(x5, x3, x5, x4, x6), PPath.of(x5, x4, x3, x4, x6), PPath.of(x5, x4, x3, x5, x6),
@@ -255,7 +240,7 @@ public class CrawlerTest extends Assert {
paths.clear(); paths.clear();
crawler.findFast(x2); crawler.findFast(x2);
assertPaths(paths.get(), PPath.of(x5, x3, x2)); TestUtil.assertPaths(paths.get(), PPath.of(x5, x3, x2));
paths.clear(); paths.clear();
} }
@@ -280,20 +265,20 @@ public class CrawlerTest extends Assert {
crawler.setStartFuel(0.3); crawler.setStartFuel(0.3);
crawler.findMin(x3, x2); crawler.findMin(x3, x2);
assertPaths(paths.get(), PPath.of(x3, x2)); TestUtil.assertPaths(paths.get(), PPath.of(x3, x2));
paths.clear(); paths.clear();
crawler.findFast(x3, x2); crawler.findFast(x3, x2);
assertPaths(paths.get(), PPath.of(x3, x2)); TestUtil.assertPaths(paths.get(), PPath.of(x3, x2));
paths.clear(); paths.clear();
crawler.setStartFuel(0.6); crawler.setStartFuel(0.6);
crawler.findMin(x6, x2); crawler.findMin(x6, x2);
assertPaths(paths.get(), PPath.of(x6, x4, x2)); TestUtil.assertPaths(paths.get(), PPath.of(x6, x4, x2));
paths.clear(); paths.clear();
crawler.findFast(x6, x2); crawler.findFast(x6, x2);
assertPaths(paths.get(), PPath.of(x6, x4, x2)); TestUtil.assertPaths(paths.get(), PPath.of(x6, x4, x2));
paths.clear(); paths.clear();
} }