private void ExpectEmptyGraph(GraphReloadResult reloadResult) { var newGraph = reloadResult.PipGraph.DirectedGraph; Assert.Equal(0, newGraph.NodeCount); Assert.Equal(0, newGraph.EdgeCount); Assert.Equal(0, reloadResult.Stats.NumPipsReloaded); }
private void ExpectGraph(GraphReloadResult reloadResult, Pip[] oldPips, string expectedPipIndexesAsString, string expectedEdgesAsString) { int[] expectedPipIndexes = expectedPipIndexesAsString.Split(',').Select(i => int.Parse(i)).ToArray(); var graph = SimpleGraph.Parse(oldPips.Length, expectedEdgesAsString); var newPipGraph = reloadResult.PipGraph; var newPipTable = newPipGraph.PipTable; var newGraph = newPipGraph.DirectedGraph; // check that the new pip table contains expected number of relevant pips var allPipTypes = new HashSet <PipType>(oldPips.Select(pip => pip.PipType).Distinct()); IEnumerable <Pip> newRelevantPips = HydratePipsByType(newPipTable, relevantTypes: allPipTypes); Assert.Equal(expectedPipIndexes.Length, newRelevantPips.Count()); // check that for all expected pips there is a node in the new graph XAssert.All( expectedPipIndexes, idx => { Assert.True(newGraph.ContainsNode(oldPips[idx].PipId.ToNodeId()), $"No graph node found for Pip{idx}"); }); // check edges var newRelevantPipIdValues = new HashSet <uint>(newRelevantPips.Select(pip => pip.PipId.Value)); XAssert.All( expectedPipIndexes, idx => { var nodeId = oldPips[idx].PipId.ToNodeId(); var expectedOutgoingEdges = graph .Edges .Where(e => e.Src == idx) .Select(e => oldPips[e.Dest].PipId.ToNodeId().Value) .OrderBy(v => v) .ToArray(); var actualOutgoingEdges = newGraph .GetOutgoingEdges(nodeId) .Select(e => e.OtherNode.Value) .Where(v => newRelevantPipIdValues.Contains(v)) .OrderBy(v => v) .ToArray(); XAssert.AreArraysEqual(expectedOutgoingEdges, actualOutgoingEdges, expectedResult: true); }); // check stats Assert.Equal(expectedPipIndexes.Length, reloadResult.Stats.NumPipsReloaded); }