//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void canUseBranchState() public virtual void CanUseBranchState() { // This test doesn't use the predefined finder, which only means an unnecessary instantiation // if such an object. And this test will be run twice (once for each finder type in data()). /// <summary> /// <pre> /// 012345 A - B: 2 /// +------>y A - B: 2 /// 0|A B - C: 3 /// 1| A - C: 10 /// 2| B /// 3| /// 4| /// 5| /// 6| /// 7|C /// V /// x /// /// </pre> /// </summary> Node nodeA = Graph.makeNode("A", "x", 0d, "y", 0d); Node nodeB = Graph.makeNode("B", "x", 2d, "y", 1d); Node nodeC = Graph.makeNode("C", "x", 7d, "y", 0d); Graph.makeEdge("A", "B", "length", 2d); Graph.makeEdge("A", "B", "length", 2d); Graph.makeEdge("B", "C", "length", 3d); Graph.makeEdge("A", "C", "length", 10d); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.Map<org.neo4j.graphdb.Node, double> seenBranchStates = new java.util.HashMap<>(); IDictionary <Node, double> seenBranchStates = new Dictionary <Node, double>(); PathExpander <double> expander = new PathExpanderAnonymousInnerClass(this, seenBranchStates); double initialStateValue = 0D; PathFinder <WeightedPath> traversalFinder = new TraversalAStar(expander, new Org.Neo4j.Graphdb.traversal.InitialBranchState_State(initialStateValue, initialStateValue), doubleCostEvaluator("length"), EstimateEvaluator); WeightedPath path = traversalFinder.FindSinglePath(nodeA, nodeC); assertEquals(( double? )5.0D, ( double? )path.Weight()); AssertPathDef(path, "A", "B", "C"); assertEquals(MapUtil.genericMap <Node, double>(nodeA, 0D, nodeB, 2D), seenBranchStates); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void canKeepSearchingUntilFoundTrueShortest() public virtual void CanKeepSearchingUntilFoundTrueShortest() { /* * * 1 - (B) - 1 - (C) - 1 - (D) - 1 - (E) - 1 * | | * (A) --- 1 --- (G) -- 2 -- (H) --- 1 --- (F) * */ Node a = Graph.makeNode( "A" ); Node b = Graph.makeNode( "B" ); Node c = Graph.makeNode( "C" ); Node d = Graph.makeNode( "D" ); Node e = Graph.makeNode( "E" ); Node f = Graph.makeNode( "F" ); Node g = Graph.makeNode( "G" ); Node h = Graph.makeNode( "H" ); Graph.makeEdgeChain( "A,B,C,D,E,F", "length", 1 ); Graph.makeEdge( "A", "G", "length", 1 ); Graph.makeEdge( "G", "H", "length", 2 ); Graph.makeEdge( "H", "F", "length", 1 ); PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() ); IEnumerator<WeightedPath> paths = finder.findAllPaths( a, f ).GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue( "Expect at least one path", paths.hasNext() ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: WeightedPath path = paths.next(); assertPath( path, a,g,h,f ); assertEquals( "Expect weight 1", 4, path.Weight(), 0.0 ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse( "Expected at most one path", paths.hasNext() ); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void canFindNeighbourMultipleIncorrectPaths() public virtual void CanFindNeighbourMultipleIncorrectPaths() { /* * - 2.0 - * / \ * (A) - 1 - (B) */ Node nodeA = Graph.makeNode( "A" ); Node nodeB = Graph.makeNode( "B" ); Graph.makeEdge( "A", "B", "length", 2.0 ); Graph.makeEdge( "A", "B", "length", 1 ); PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() ); IEnumerator<WeightedPath> paths = finder.findAllPaths( nodeA, nodeB ).GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue( "Expect at least one path", paths.hasNext() ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: WeightedPath path = paths.next(); assertPath( path, nodeA, nodeB ); assertEquals( "Expect weight 1", 1, path.Weight(), 0.0 ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse( "Expected at most one path", paths.hasNext() ); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testKShortestPaths() public virtual void TestKShortestPaths() { /* * ----- (e) - 3 - (f) --- * / \ * / ------- (a) -------- \ * 3 / \ \ 3 * | 2 0 0 | * | / \ \| * (s) - 1 - (c) - 1 - (d) - 1 - (t) * \ / * -- 1 - (b) - 1 - * */ Node s = Graph.makeNode("s"); Node t = Graph.makeNode("t"); Graph.makeEdge("s", "a", "length", 2); Graph.makeEdge("s", "b", "length", 1); Graph.makeEdge("s", "c", "length", 1); Graph.makeEdge("s", "e", "length", 3); Graph.makeEdge("a", "t", "length", 0); Graph.makeEdge("b", "d", "length", 1); Graph.makeEdge("c", "d", "length", 1); Graph.makeEdge("d", "a", "length", 0); Graph.makeEdge("d", "t", "length", 1); Graph.makeEdge("e", "f", "length", 3); Graph.makeEdge("f", "t", "length", 3); PathExpander expander = PathExpanders.allTypesAndDirections(); PathFinder <WeightedPath> algo = new Dijkstra(expander, CommonEvaluators.doubleCostEvaluator("length"), PathInterestFactory.numberOfShortest(NoneStrictMath.EPSILON, 6)); IEnumerator <WeightedPath> paths = algo.FindAllPaths(s, t).GetEnumerator(); int count = 0; while (paths.MoveNext()) { count++; WeightedPath path = paths.Current; double expectedWeight; if (count <= 3) { expectedWeight = 2.0; } else { expectedWeight = 3.0; } assertTrue("Expected path number " + count + " to have weight of " + expectedWeight, NoneStrictMath.Equals(path.Weight(), expectedWeight)); } assertEquals("Expected exactly 6 returned paths", 6, count); }