コード例 #1
0
        public void GetEdge_Throws()
        {
            var graph  = new AdjacencyGraph <int, Edge <int> >();
            var graph2 = new AdjacencyGraph <TestVertex, Edge <TestVertex> >();
            var random = new Random();

            // ReSharper disable ReturnValueOfPureMethodIsNotUsed
            // ReSharper disable AssignNullToNotNullAttribute
            Assert.Throws <ArgumentNullException>(() => RandomGraphFactory.GetEdge <int, Edge <int> >(null, random));
            Assert.Throws <ArgumentNullException>(() => RandomGraphFactory.GetEdge(graph2, null));
            Assert.Throws <ArgumentNullException>(() => RandomGraphFactory.GetEdge <int, Edge <int> >(null, null));

            Assert.Throws <ArgumentNullException>(() => RandomGraphFactory.GetEdge <int, Edge <int> >(null, 1, random));
            Assert.Throws <ArgumentNullException>(() => RandomGraphFactory.GetEdge <int, Edge <int> >(Enumerable.Empty <Edge <int> >(), 1, null));
            Assert.Throws <ArgumentNullException>(() => RandomGraphFactory.GetEdge <int, Edge <int> >(null, 1, null));
            // ReSharper restore AssignNullToNotNullAttribute
            Assert.Throws <ArgumentOutOfRangeException>(() => RandomGraphFactory.GetVertex(graph, random));

            Assert.Throws <ArgumentOutOfRangeException>(() => RandomGraphFactory.GetEdge <int, Edge <int> >(Enumerable.Empty <Edge <int> >(), -1, random));
            Assert.Throws <ArgumentOutOfRangeException>(() => RandomGraphFactory.GetEdge <int, Edge <int> >(Enumerable.Empty <Edge <int> >(), 0, random));
            Assert.Throws <InvalidOperationException>(() => RandomGraphFactory.GetEdge <int, Edge <int> >(Enumerable.Empty <Edge <int> >(), 1, random));
            Assert.Throws <InvalidOperationException>(
                () => RandomGraphFactory.GetEdge <int, Edge <int> >(
                    new[] { new Edge <int>(1, 2), new Edge <int>(1, 3) },
                    10,
                    new Random(123456)));
            // ReSharper restore ReturnValueOfPureMethodIsNotUsed
        }
コード例 #2
0
        public void GetEdge()
        {
            var graph  = new AdjacencyGraph <int, Edge <int> >();
            var edge12 = new Edge <int>(1, 2);
            var edge13 = new Edge <int>(1, 3);
            var edge23 = new Edge <int>(2, 3);
            var edge24 = new Edge <int>(2, 4);
            var edge35 = new Edge <int>(3, 5);

            graph.AddVerticesAndEdgeRange(new[]
            {
                edge12, edge13, edge23, edge24, edge35
            });

            Edge <int> edge = RandomGraphFactory.GetEdge(graph, new Random(123456));

            Assert.AreSame(edge13, edge);

            edge = RandomGraphFactory.GetEdge(graph, new Random(456789));
            Assert.AreSame(edge35, edge);

            edge = RandomGraphFactory.GetEdge <int, Edge <int> >(graph.Edges, graph.VertexCount, new Random(123456));
            Assert.AreSame(edge13, edge);

            edge = RandomGraphFactory.GetEdge <int, Edge <int> >(graph.Edges, graph.VertexCount, new Random(456789));
            Assert.AreSame(edge35, edge);

            edge = RandomGraphFactory.GetEdge <int, Edge <int> >(graph.Edges, 3, new Random(123));
            Assert.AreSame(edge23, edge);
        }