Beispiel #1
0
    public void DijkstraTest()
    {
        // Check the links of vertices
        // Arrange----------------------------------------------------------------------------
        Dijkstra dijkstra = new Dijkstra();
        Graph    graph    = new Graph(@"C:\Users\Paul\Documents\Open Source Society for Computer Science (OSSU)\Algorithms Coursera\Programming Assignments\Week 6 Programming Assignment\Unit Test Data.txt");
        SortedDictionary <int?, List <Vertex> > myPaths = dijkstra.Apply(graph, graph._vertices[1]);

        int?[] vNum    = new int?[4];
        int?[] testNum = new int?[4];

        // Assert
        Assert.Equal(null, graph._vertices[1]._link);
        Assert.Equal(1, graph._vertices[2]._link._number);
        Assert.Equal(2, graph._vertices[3]._link._number);
        Assert.Equal(3, graph._vertices[4]._link._number);

        //-Making Paths Dictionary---------------------------------------------------
        // Arrange
        int?[] truePathsLength = new int?[4];
        int?[] truePath_1      = { null };
        int?[] truePath_2      = { 1, 2 };
        int?[] truePath_3      = { 1, 2, 3 };
        int?[] truePath_4      = { 1, 2, 3, 4 };


        // Assert
        Assert.Equal(truePathsLength.Length, dijkstra._myPath.Count);

        Assert.Equal(0, graph._vertices[1]._dijkstraLength);
        Assert.Equal(null, dijkstra._myPath[1][0]._link);

        Assert.Equal(1, graph._vertices[2]._dijkstraLength);
        for (int i = 0; i < 2; i++)
        {
            Assert.Equal(truePath_2[i], myPaths[2][i]._number);
        }

        Assert.Equal(3, graph._vertices[3]._dijkstraLength);
        for (int i = 0; i < 3; i++)
        {
            Assert.Equal(truePath_3[i], myPaths[3][i]._number);
        }

        Assert.Equal(6, graph._vertices[4]._dijkstraLength);
        for (int i = 0; i < 4; i++)
        {
            Assert.Equal(truePath_4[i], myPaths[4][i]._number);
        }
    }
Beispiel #2
0
    public void TestCase1()
    {
        // Arrange
        Dijkstra dijkstra = new Dijkstra();
        Graph    graph    = new Graph(@"C:\Users\Paul\Documents\Open Source Society for Computer Science (OSSU)\Algorithms Coursera\Programming Assignments\Week 6 Programming Assignment\Test Case.txt");
        SortedDictionary <int?, List <Vertex> > myPaths = dijkstra.Apply(graph, graph._vertices[1]);

        int?[] truePathsLength = new int?[8];
        int?[] truePath_1      = { null };
        int?[] truePath_2      = { 1, 2 };
        int?[] truePath_3      = { 1, 2, 3 };
        int?[] truePath_4      = { 1, 2, 3, 4 };
        int?[] truePath_5      = { 1, 2, 3, 4, 5 };
        int?[] truePath_6      = { 1, 8, 7, 6 };
        int?[] truePath_7      = { 1, 8, 7 };
        int?[] truePath_8      = { 1, 8 };

        Assert.Equal(truePathsLength.Length, dijkstra._myPath.Count);

        Assert.Equal(0, graph._vertices[1]._dijkstraLength);
        Assert.Equal(null, dijkstra._myPath[1][0]._link);

        Assert.Equal(1, graph._vertices[2]._dijkstraLength);
        for (int i = 0; i < 2; i++)
        {
            Assert.Equal(truePath_2[i], myPaths[2][i]._number);
        }

        Assert.Equal(2, graph._vertices[3]._dijkstraLength);
        for (int i = 0; i < 3; i++)
        {
            Assert.Equal(truePath_3[i], myPaths[3][i]._number);
        }

        Assert.Equal(3, graph._vertices[4]._dijkstraLength);
        for (int i = 0; i < 4; i++)
        {
            Assert.Equal(truePath_4[i], myPaths[4][i]._number);
        }

        Assert.Equal(4, graph._vertices[5]._dijkstraLength);
        for (int i = 0; i < 5; i++)
        {
            Assert.Equal(truePath_5[i], myPaths[5][i]._number);
        }

        Assert.Equal(4, graph._vertices[6]._dijkstraLength);
        for (int i = 0; i < 4; i++)
        {
            Assert.Equal(truePath_6[i], myPaths[6][i]._number);
        }

        Assert.Equal(3, graph._vertices[7]._dijkstraLength);
        for (int i = 0; i < 3; i++)
        {
            Assert.Equal(truePath_7[i], myPaths[7][i]._number);
        }

        Assert.Equal(2, graph._vertices[8]._dijkstraLength);
        for (int i = 0; i < 2; i++)
        {
            Assert.Equal(truePath_8[i], myPaths[8][i]._number);
        }
    }