コード例 #1
0
        public void testAddstringDuplicate()
        {
            AdjacencyListGraph <string, string> g = graph();

            Assert.IsTrue(g.AddNode(n1));
            Assert.IsFalse(g.AddNode(n1));
        }
コード例 #2
0
        public void testAddstringMultiple()
        {
            AdjacencyListGraph <string, string> g = graph();

            Assert.IsTrue(g.AddNode(n1));
            Assert.IsTrue(g.AddNode(n2));
        }
コード例 #3
0
        public void testSetEdgeDataNull()
        {
            AdjacencyListGraph <object, string> g = new AdjacencyListGraph <object, string>();

            g.AddNode(n1);
            g.AddNode(n2);
            g.AddEdge(e1);
            g.ReplaceEdge <object, string, string>(null, "");
        }
コード例 #4
0
    private IGraph <Vector2> GetMazeGraph()
    {
        IGraph <Vector2> graph = new AdjacencyListGraph <Vector2>();

        IGraphNode <Vector2>[,] nodes = new IGraphNode <Vector2> [size, size];

        for (int y = 0; y < size; ++y)
        {
            for (int x = 0; x < size; ++x)
            {
                nodes[y, x] = graph.AddNode(new Vector2(x, y));
            }
        }

        for (int i = 1; i < size; ++i)
        {
            graph.AddUndirectedEdge(nodes[i - 1, 0], nodes[i, 0], Random.Range(0f, 1f));
            graph.AddUndirectedEdge(nodes[0, i - 1], nodes[0, i], Random.Range(0f, 1f));
        }

        for (int y = 1; y < size; ++y)
        {
            for (int x = 1; x < size; ++x)
            {
                graph.AddUndirectedEdge(nodes[y - 1, x], nodes[y, x], Random.Range(0f, 1f));
                graph.AddUndirectedEdge(nodes[y, x - 1], nodes[y, x], Random.Range(0f, 1f));
            }
        }

        IMSTStrategy <Vector2> strategy = new KruskalsAlgorithm <Vector2>();

        return(new MSTResultGraph <Vector2>(graph, strategy));
    }
コード例 #5
0
        // convenient way to get a new graph with m strings.
        private static AdjacencyListGraph <string, string> graph(params string[] args)
        {
            AdjacencyListGraph <string, string> g = new AdjacencyListGraph <string, string>();

            foreach (string arg in args)
            {
                g.AddNode(arg);
            }
            return(g);
        }
コード例 #6
0
        public void testRemovestringWithParentsAndAddAgain()
        {
            AdjacencyListGraph <string, string> g = graph(n1, n2);

            g.AddEdge(e1);

            g.RemoveNode(n2);
            g.AddNode(n2);
            Assert.IsTrue(g.ContainsNode(n2));
            Assert.IsFalse(g.ContainsEdge(e1));
            g.AddEdge(e1);
            Assert.IsTrue(g.ContainsEdge(e1));
        }
コード例 #7
0
        public void testAddstringNull()
        {
            AdjacencyListGraph <string, string> g = graph();

            g.AddNode(null);
        }