protected static void Degree_Throws_Test <TVertex, TEdge>( [NotNull] IBidirectionalIncidenceGraph <TVertex, TEdge> graph) where TVertex : class, IEquatable <TVertex>, new() where TEdge : IEdge <TVertex> { // ReSharper disable ReturnValueOfPureMethodIsNotUsed // ReSharper disable once AssignNullToNotNullAttribute Assert.Throws <ArgumentNullException>(() => graph.Degree(null)); Assert.Throws <VertexNotFoundException>(() => graph.Degree(new TVertex())); // ReSharper restore ReturnValueOfPureMethodIsNotUsed }
protected static void Degree_ImmutableGraph_ReversedTest( [NotNull] IMutableVertexAndEdgeSet <int, Edge <int> > wrappedGraph, [NotNull, InstantHandle] Func <IBidirectionalIncidenceGraph <int, SReversedEdge <int, Edge <int> > > > createGraph) { var edge1 = new Edge <int>(1, 2); var edge2 = new Edge <int>(1, 3); var edge3 = new Edge <int>(1, 4); var edge4 = new Edge <int>(2, 4); var edge5 = new Edge <int>(3, 2); var edge6 = new Edge <int>(3, 3); wrappedGraph.AddVerticesAndEdgeRange(new[] { edge1, edge2, edge3, edge4, edge5, edge6 }); wrappedGraph.AddVertex(5); IBidirectionalIncidenceGraph <int, SReversedEdge <int, Edge <int> > > graph = createGraph(); Assert.AreEqual(3, graph.Degree(1)); Assert.AreEqual(3, graph.Degree(2)); Assert.AreEqual(4, graph.Degree(3)); // Self edge Assert.AreEqual(2, graph.Degree(4)); Assert.AreEqual(0, graph.Degree(5)); }
protected static void Degree_Test( [NotNull] GraphData <int, Edge <int> > data1, [NotNull] GraphData <int, Edge <int> > data2, [NotNull] IBidirectionalIncidenceGraph <int, Edge <int> > graph) { // ReSharper disable ReturnValueOfPureMethodIsNotUsed data1.CheckCalls(0); data2.CheckCalls(0); data1.ShouldReturnValue = false; data2.ShouldReturnValue = false; Assert.Throws <VertexNotFoundException>(() => graph.Degree(1)); data1.CheckCalls(0); data2.CheckCalls(1); data1.ShouldReturnValue = true; data2.ShouldReturnValue = false; Assert.Throws <VertexNotFoundException>(() => graph.Degree(1)); data1.CheckCalls(0); data2.CheckCalls(1); data1.ShouldReturnValue = false; data2.ShouldReturnValue = true; Assert.Throws <VertexNotFoundException>(() => graph.Degree(1)); data1.CheckCalls(1); data2.CheckCalls(1); // ReSharper restore ReturnValueOfPureMethodIsNotUsed data1.ShouldReturnValue = true; data2.ShouldReturnValue = true; Assert.AreEqual(0, graph.Degree(1)); data1.ShouldReturnEdges = new[] { new Edge <int>(1, 2) }; data2.ShouldReturnEdges = null; Assert.AreEqual(1, graph.Degree(1)); data1.ShouldReturnEdges = null; data2.ShouldReturnEdges = new[] { new Edge <int>(3, 1) }; Assert.AreEqual(1, graph.Degree(1)); data1.ShouldReturnEdges = new[] { new Edge <int>(1, 2), new Edge <int>(1, 3) }; data2.ShouldReturnEdges = new[] { new Edge <int>(4, 1) }; Assert.AreEqual(3, graph.Degree(1)); // Self edge data1.ShouldReturnEdges = new[] { new Edge <int>(1, 2), new Edge <int>(1, 3), new Edge <int>(1, 1) }; data2.ShouldReturnEdges = new[] { new Edge <int>(4, 1), new Edge <int>(1, 1) }; Assert.AreEqual(5, graph.Degree(1)); }