Graphs { public static <E extends ConnectionData> void addBiPath(Graph<E> graph, Point... path) { addPath(graph, path); final List<Point> list = Arrays.asList(path); Collections.reverse(list); addPath(graph, list.toArray(new Point[path.length])); } private  Graphs(); static void addPath(Graph<E> graph,
      Point... path); static void addPath(Graph<E> graph,
      Iterable<Point> path); static void addBiPath(Graph<E> graph,
      Point... path); static void addBiPath(Graph<E> graph,
      Iterable<Point> path); static Graph<E> unmodifiableGraph(
      Graph<E> graph); static boolean equal(Graph<?> g1, @Nullable Object other); static List<Point> shortestPathEuclideanDistance(
      Graph<E> graph, final Point from, final Point to); static List<Point> shortestPath(
      Graph<E> graph, final Point from, final Point to, GeomHeuristic h); @Nullable static T findClosestObject(Point pos, Collection<T> objects,
      Function<T, Point> transformation); static List<T> findClosestObjects(Point pos,
      Collection<T> objects, Function<T, Point> transformation, int n); static double pathLength(List<Point> path); static ImmutableList<Point> getExtremes(Graph<?> graph);  }
@Test public void equalsTest() { assertFalse(graph.equals(new Object())); assertEquals(graph, graph); final Point N = new Point(0, 5); final Point E = new Point(5, 0); final Point S = new Point(0, -5); final Point W = new Point(-5, 0); Graphs.addBiPath(graph, N, E, S, W, N); assertEquals(graph, graph); final Graph<LengthData> g1 = new TableGraph<>(); g1.merge(graph); assertEquals(g1, graph); final Graph<LengthData> g2 = new MultimapGraph<>(); g2.merge(graph); assertEquals(g2, graph); assertEquals(g1, g2); g1.removeConnection(N, E); assertFalse(g1.equals(graph)); g1.removeNode(N); assertFalse(g1.equals(graph)); final Point C = new Point(0, 0); Graphs.addBiPath(g1, W, C, E); assertFalse(g1.equals(graph)); graph.removeConnection(N, E); graph.addConnection(N, E, LengthData.create(10)); assertFalse(g1.equals(graph)); assertFalse(graph.equals(g1)); final Graph<LengthData> g3 = new TableGraph<>(); g3.merge(graph); assertEquals(graph, g3); g3.removeConnection(N, E); g3.addConnection(N, E, LengthData.create(9)); assertFalse(g3.equals(graph)); assertFalse(g2.equals(graph)); assertFalse(g2.equals(g3)); assertFalse(graph.equals(g2)); assertFalse(g3.equals(g2)); }
@Test(expected = IllegalArgumentException.class) public void addExistingConnection() { final Point N = new Point(0, 5); final Point E = new Point(5, 0); Graphs.addBiPath(graph, N, E); Graphs.addBiPath(graph, N, E); }
@Test public void testMultimapGraphConstructor() { final RandomGenerator rnd = new MersenneTwister(123); final List<Point> path = new ArrayList<Point>(); for (int i = 0; i < 20; i++) { path.add(new Point(rnd.nextInt(50), rnd.nextInt(50))); } Graphs.addBiPath(graph, path.toArray(new Point[path.size()])); final MultimapGraph<LengthData> testGraph = new MultimapGraph<>(); testGraph.merge(graph); final MultimapGraph<LengthData> newGraph = new MultimapGraph<>( testGraph.getMultimap()); assertEquals(testGraph.getMultimap(), newGraph.getMultimap()); }
@Test public void setConnData() { final Point N = new Point(0, 5); final Point E = new Point(5, 0); final Point S = new Point(0, -5); final Point W = new Point(-5, 0); Graphs.addBiPath(graph, N, E, S, W, N); assertFalse(graph.setConnectionData(N, E, LengthData.create(100)) .isPresent()); assertEquals(LengthData.create(100), graph.removeConnectionData(N, E).get()); }
@Test public void getRandomNodeImpossible() { Point A, B, C, D; A = new Point(0, 0); B = new Point(0, 10); C = new Point(10, 10); D = new Point(10, 0); Graphs.addBiPath(graph, A, B, C, D, A); final RandomGenerator rg = new RandomGenerator() { @Override public void setSeed(long arg0) { } @Override public void setSeed(@Nullable int[] arg0) { } @Override public void setSeed(int arg0) { } @Override public long nextLong() { return 0; } @Override public int nextInt(int arg0) { return arg0 + 1; } @Override public int nextInt() { return 0; } @Override public double nextGaussian() { return 0; } @Override public float nextFloat() { return 0; } @Override public double nextDouble() { return 0; } @Override public void nextBytes(@Nullable byte[] arg0) {} @Override public boolean nextBoolean() { return false; } }; boolean flag = false; try { graph.getRandomNode(rg); } catch (final IllegalStateException e) { flag = true; } assertTrue(flag); }