public void GetEdge_Throws()
        {
            var graph  = new AdjacencyGraph <int, Edge <int> >();
            var graph2 = new AdjacencyGraph <TestVertex, Edge <TestVertex> >();
            var random = new QuikGraph.Utils.CryptoRandom();

            // 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
        }
Example #2
0
        protected static UndirectedGraph <string, TaggedEdge <string, double> > GetUndirectedCompleteGraph(int vertex)
        {
            var random    = new QuikGraph.Utils.CryptoRandom();
            var graph     = new UndirectedGraph <string, TaggedEdge <string, double> >();
            var trueGraph = new UndirectedGraph <string, TaggedEdge <string, double> >();
            var sets      = new ForestDisjointSet <string>(vertex);

            for (int i = 0; i < vertex; ++i)
            {
                graph.AddVertex(i.ToString());
                trueGraph.AddVertex(i.ToString());
                sets.MakeSet(i.ToString());
            }

            for (int i = 0; i < vertex; ++i)
            {
                for (int j = i + 1; j < vertex; ++j)
                {
                    graph.AddEdge(
                        new TaggedEdge <string, double>(
                            i.ToString(),
                            j.ToString(),
                            random.Next(100)));
                }
            }

            return(graph);
        }
        public void EdgeCondensation()
        {
            var rand = new QuikGraph.Utils.CryptoRandom(123456);

            foreach (BidirectionalGraph <string, Edge <string> > graph in TestGraphFactory.GetBidirectionalGraphs_SlowTests())
            {
                RunEdgesCondensationAndCheck(graph, v => true);
                RunEdgesCondensationAndCheck(graph, v => rand.Next(0, 1) == 1);
            }
        }
Example #4
0
        public void ToDirectedGraphML_WithColors()
        {
            var random = new QuikGraph.Utils.CryptoRandom(123456);

            foreach (AdjacencyGraph <string, Edge <string> > graph in TestGraphFactory.GetAdjacencyGraphs_All())
            {
                Dictionary <string, GraphColor> vertexColors = graph.Vertices.ToDictionary(
                    vertex => vertex,
                    vertex => (GraphColor)random.Next(0, 3));

                DirectedGraph directedGraph = graph.ToDirectedGraphML(
                    vertex =>
                {
                    Assert.IsNotNull(vertex);
                    return(vertexColors[vertex]);
                });
                Assert.IsNotNull(graph);

                AssertGraphContentEquivalent(graph, directedGraph);

                foreach (DirectedGraphNode node in directedGraph.Nodes)
                {
                    Assert.AreEqual(
                        ColorToStringColor(vertexColors[node.Id]),
                        node.Background);
                }
            }

            #region Local function

            string ColorToStringColor(GraphColor color)
            {
                switch (color)
                {
                case GraphColor.Black:
                    return("Black");

                case GraphColor.Gray:
                    return("LightGray");

                case GraphColor.White:
                    return("White");

                default:
                    Assert.Fail("Unknown color.");
                    return(string.Empty);
                }
            }

            #endregion
        }
        public void Create_Throws()
        {
            var graph  = new AdjacencyGraph <int, Edge <int> >();
            var random = new QuikGraph.Utils.CryptoRandom();

            // ReSharper disable AssignNullToNotNullAttribute
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    (IMutableVertexAndEdgeListGraph <int, Edge <int> >)null,
                    () => 1,
                    (source, target) => new Edge <int>(source, target),
                    random,
                    1, 1, false));
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    graph,
                    null,
                    (source, target) => new Edge <int>(source, target),
                    random,
                    1, 1, false));
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    graph,
                    () => 1,
                    null,
                    random,
                    1, 1, false));
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    graph,
                    () => 1,
                    (source, target) => new Edge <int>(source, target),
                    null,
                    1, 1, false));
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    (IMutableVertexAndEdgeListGraph <int, Edge <int> >)null,
                    null,
                    (source, target) => new Edge <int>(source, target),
                    random,
                    1, 1, false));
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    (IMutableVertexAndEdgeListGraph <int, Edge <int> >)null,
                    () => 1,
                    null,
                    random,
                    1, 1, false));
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    (IMutableVertexAndEdgeListGraph <int, Edge <int> >)null,
                    () => 1,
                    (source, target) => new Edge <int>(source, target),
                    null,
                    1, 1, false));
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    graph,
                    null,
                    null,
                    random,
                    1, 1, false));
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    graph,
                    null,
                    (source, target) => new Edge <int>(source, target),
                    null,
                    1, 1, false));
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    graph,
                    () => 1,
                    null,
                    null,
                    1, 1, false));
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    graph,
                    null,
                    null,
                    null,
                    1, 1, false));
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    (IMutableVertexAndEdgeListGraph <int, Edge <int> >)null,
                    () => 1,
                    null,
                    null,
                    1, 1, false));
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    (IMutableVertexAndEdgeListGraph <int, Edge <int> >)null,
                    null,
                    (source, target) => new Edge <int>(source, target),
                    null,
                    1, 1, false));
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    (IMutableVertexAndEdgeListGraph <int, Edge <int> >)null,
                    null,
                    null,
                    random,
                    1, 1, false));
            Assert.Throws <ArgumentNullException>(
                () => RandomGraphFactory.Create(
                    (IMutableVertexAndEdgeListGraph <int, Edge <int> >)null,
                    null,
                    null,
                    null,
                    1, 1, false));
            // ReSharper restore AssignNullToNotNullAttribute
            Assert.Throws <ArgumentOutOfRangeException>(
                () => RandomGraphFactory.Create(
                    graph,
                    () => 1,
                    (source, target) => new Edge <int>(source, target),
                    random,
                    -1, 1, false));
            Assert.Throws <ArgumentOutOfRangeException>(
                () => RandomGraphFactory.Create(
                    graph,
                    () => 1,
                    (source, target) => new Edge <int>(source, target),
                    random,
                    0, 1, false));
            Assert.Throws <ArgumentOutOfRangeException>(
                () => RandomGraphFactory.Create(
                    graph,
                    () => 1,
                    (source, target) => new Edge <int>(source, target),
                    random,
                    1, -1, false));
            Assert.Throws <ArgumentOutOfRangeException>(
                () => RandomGraphFactory.Create(
                    graph,
                    () => 1,
                    (source, target) => new Edge <int>(source, target),
                    random,
                    1, 0, false));
            Assert.Throws <ArgumentOutOfRangeException>(
                () => RandomGraphFactory.Create(
                    graph,
                    () => 1,
                    (source, target) => new Edge <int>(source, target),
                    random,
                    0, 0, false));
            Assert.Throws <ArgumentOutOfRangeException>(
                () => RandomGraphFactory.Create(
                    graph,
                    () => 1,
                    (source, target) => new Edge <int>(source, target),
                    random,
                    -1, -1, false));
        }