From 40e4d2b37715123631f449e00960ebc1e407ec91 Mon Sep 17 00:00:00 2001 From: iMoHax Date: Wed, 15 Jul 2015 11:24:33 +0300 Subject: [PATCH] move to test util check paths --- core/src/test/java/ru/trader/TestUtil.java | 18 +++++++ .../ru/trader/analysis/graph/CrawlerTest.java | 51 +++++++------------ 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/core/src/test/java/ru/trader/TestUtil.java b/core/src/test/java/ru/trader/TestUtil.java index 29b3e97..d82e96e 100644 --- a/core/src/test/java/ru/trader/TestUtil.java +++ b/core/src/test/java/ru/trader/TestUtil.java @@ -2,9 +2,13 @@ package ru.trader; 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.Iterator; +import java.util.List; public class TestUtil { @@ -113,4 +117,18 @@ public class TestUtil { checkContains(collection, true, items); } + public static void assertPaths(Collection>> paths, PPath... points) { + assertPaths(false, paths, points); + } + + public static void assertPaths(boolean saveOrder, Collection>> paths, PPath... points){ + Collection actual = new ArrayList<>(paths.size()); + paths.forEach(p -> actual.add(PPath.of(p))); + if (saveOrder) { + TestUtil.assertCollectionEquals(actual, points); + } else { + TestUtil.assertCollectionContainAll(actual, points); + } + } + } diff --git a/core/src/test/java/ru/trader/analysis/graph/CrawlerTest.java b/core/src/test/java/ru/trader/analysis/graph/CrawlerTest.java index 496ed62..c095228 100644 --- a/core/src/test/java/ru/trader/analysis/graph/CrawlerTest.java +++ b/core/src/test/java/ru/trader/analysis/graph/CrawlerTest.java @@ -11,7 +11,6 @@ import ru.trader.core.Profile; import ru.trader.core.Ship; import java.util.ArrayList; -import java.util.Collection; import java.util.List; public class CrawlerTest extends Assert { @@ -60,20 +59,6 @@ public class CrawlerTest extends Assert { } } - private void assertPaths(List>> paths, PPath... points) { - assertPaths(false, paths, points); - } - - private void assertPaths(boolean saveOrder, List>> paths, PPath... points){ - Collection 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 public void testGetPaths() throws Exception { LOG.info("Start get paths test"); @@ -90,11 +75,11 @@ public class CrawlerTest extends Assert { SimpleCollector paths = new SimpleCollector<>(); Crawler crawler = new CCrawler<>(graph, paths::add); crawler.findMin(x4, 10); - assertPaths(paths.get(), PPath.of(x5, x4)); + TestUtil.assertPaths(paths.get(), PPath.of(x5, x4)); paths.clear(); crawler.findMin(x6, 10); - assertPaths(paths.get(), PPath.of(x5, x6)); + TestUtil.assertPaths(paths.get(), PPath.of(x5, x6)); paths.clear(); crawler.findMin(x7, 10); @@ -120,20 +105,20 @@ public class CrawlerTest extends Assert { Crawler crawler = new CCrawler<>(graph, paths::add); 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(); 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(); crawler.findMin(x7); assertEquals(1, paths.get().size()); - assertPaths(paths.get(), PPath.of(x5, x6, x7)); + TestUtil.assertPaths(paths.get(), PPath.of(x5, x6, x7)); paths.clear(); 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, x4, x6, x4), PPath.of(x5, x6, x3, x4), PPath.of(x5, x3, x5, x4), PPath.of(x5, x4, x2, x4), @@ -147,7 +132,7 @@ public class CrawlerTest extends Assert { paths.clear(); 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, x3, x4, x5), PPath.of(x5, x3, x6, x5)); paths.clear(); @@ -158,7 +143,7 @@ public class CrawlerTest extends Assert { crawler.findFast(x7, 10); 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(); crawler.findFast(x4); @@ -188,11 +173,11 @@ public class CrawlerTest extends Assert { paths.clear(); 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(); 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, x3, x4, x6), PPath.of(x5, x3, x5, x6), PPath.of(x5, x6, x4, x6)); @@ -203,7 +188,7 @@ public class CrawlerTest extends Assert { paths.clear(); crawler.findFast(x2); - assertPaths(paths.get(), PPath.of(x5, x3, x2)); + TestUtil.assertPaths(paths.get(), PPath.of(x5, x3, x2)); paths.clear(); } @@ -231,7 +216,7 @@ public class CrawlerTest extends Assert { paths.clear(); 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, 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), @@ -239,7 +224,7 @@ public class CrawlerTest extends Assert { paths.clear(); 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, 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), @@ -255,7 +240,7 @@ public class CrawlerTest extends Assert { paths.clear(); crawler.findFast(x2); - assertPaths(paths.get(), PPath.of(x5, x3, x2)); + TestUtil.assertPaths(paths.get(), PPath.of(x5, x3, x2)); paths.clear(); } @@ -280,20 +265,20 @@ public class CrawlerTest extends Assert { crawler.setStartFuel(0.3); crawler.findMin(x3, x2); - assertPaths(paths.get(), PPath.of(x3, x2)); + TestUtil.assertPaths(paths.get(), PPath.of(x3, x2)); paths.clear(); crawler.findFast(x3, x2); - assertPaths(paths.get(), PPath.of(x3, x2)); + TestUtil.assertPaths(paths.get(), PPath.of(x3, x2)); paths.clear(); crawler.setStartFuel(0.6); crawler.findMin(x6, x2); - assertPaths(paths.get(), PPath.of(x6, x4, x2)); + TestUtil.assertPaths(paths.get(), PPath.of(x6, x4, x2)); paths.clear(); crawler.findFast(x6, x2); - assertPaths(paths.get(), PPath.of(x6, x4, x2)); + TestUtil.assertPaths(paths.get(), PPath.of(x6, x4, x2)); paths.clear(); }