示例#1
0
        public void MyLinkedList_5_Insert_14_GetMiddleOkAfterInsertInMiddleOnList3()
        {
            // Arrange
            IMyLinkedList <string> lst = DSBuilder.CreateMyLinkedList();

            lst.AddFirst("1");
            lst.AddFirst("2");
            lst.AddFirst("3");
            string expected = "4";

            // Act
            lst.Insert(1, "4");
            lst.RemoveFirst();
            string actual = lst.GetFirst();

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#2
0
        public void MyArrayList_8_CountOccurences_5_ReturnsProperResultAfterClean()
        {
            // Arrange
            IMyArrayList lst      = DSBuilder.CreateMyArrayList();
            int          expected = 0;

            // Act
            lst.Add(3);
            lst.Add(2);
            lst.Add(3);
            lst.Add(4);
            lst.Add(3);
            lst.Clear();
            int actual = lst.CountOccurences(3);

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#3
0
        public void MyArrayList_2_Add_3_CapacityAlmostFull()
        {
            // Arrange
            IMyArrayList lst      = DSBuilder.CreateMyArrayList();
            int          expected = 5;

            lst.Add(3);
            lst.Add(3);
            lst.Add(3);
            lst.Add(3);
            lst.Add(3);

            // Act
            int actual = lst.Size();

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#4
0
        public void MyArrayList_6_ToString_5_AfterClear()
        {
            // Arrange
            IMyArrayList lst      = DSBuilder.CreateMyArrayList();
            String       expected = "NIL";

            // Act
            lst.Add(1);
            lst.Add(2);
            lst.Add(3);
            lst.Add(4);
            lst.Add(5);
            lst.Clear();
            String actual = lst.ToString();

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#5
0
        public void MyArrayList_6_ToString_4_AfterSet()
        {
            // Arrange
            IMyArrayList lst      = DSBuilder.CreateMyArrayList();
            String       expected = "[1,2,7,4,5]";

            // Act
            lst.Add(1);
            lst.Add(2);
            lst.Add(3);
            lst.Add(4);
            lst.Add(5);
            lst.Set(2, 7);
            String actual = lst.ToString();

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#6
0
        public void MyArrayList_5_Clear_2_SizeEquals0()
        {
            // Arrange
            IMyArrayList lst      = DSBuilder.CreateMyArrayList();
            int          expected = 0;

            lst.Add(1);
            lst.Add(2);
            lst.Add(3);
            lst.Add(4);

            // Act
            lst.Clear();
            int actual = lst.Size();

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#7
0
        public void MyArrayList_5_Clear_1_CapacityRemainsSame()
        {
            // Arrange
            IMyArrayList lst      = DSBuilder.CreateMyArrayList();
            int          expected = 5;

            lst.Add(1);
            lst.Add(2);
            lst.Add(3);
            lst.Add(4);

            // Act
            lst.Clear();
            int actual = lst.Capacity();

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#8
0
        public void MyArrayList_4_Set_1_GetReturnsProperResult()
        {
            // Arrange
            IMyArrayList lst      = DSBuilder.CreateMyArrayList();
            int          expected = 7;

            lst.Add(1);
            lst.Add(2);
            lst.Add(3);
            lst.Add(4);

            // Act
            lst.Set(1, 7);
            int actual = lst.Get(1);

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#9
0
        public void MyLinkedList_7_Internal_3_Insert()
        {
            // Arrange
            MyLinkedList <string> lst = (MyLinkedList <string>)DSBuilder.CreateMyLinkedList();

            lst.AddFirst("1");
            lst.AddFirst("2");
            lst.AddFirst("3");

            // Act
            lst.Insert(1, "4");

            // Assert
            Assert.IsNotNull(lst.head);
            Assert.IsNotNull(lst.head.next);
            Assert.IsNotNull(lst.head.next.next);
            Assert.IsNotNull(lst.head.next.next.next);
            Assert.IsNull(lst.head.next.next.next.next);
        }
示例#10
0
        public void Graph_05_ToString_05_OnUnweightedGraphFromLectureExample()
        {
            // Arrange
            IGraph graph    = DSBuilder.CreateGraphFromLectureUnweightedExample();
            string expected = TestUtils.TrimmedStringWithoutSpaces(@"
                v1 [ v2(1) v4(1) ]
                v2 [ v4(1) v5(1) ]
                v3 [ v1(1) v6(1) ]
                v4 [ v3(1) v5(1) v6(1) ]
                v5 [ v7(1) ]
                v6 [ ]
                v7 [ v4(1) v6(1) ]");

            // Act
            string actual = TestUtils.TrimmedStringWithoutSpaces(graph.ToString());

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#11
0
        public void Graph_05_ToString_04_OnGraph14_1()
        {
            // Arrange
            IGraph graph    = DSBuilder.CreateGraphFromBook14_1();
            string expected = TestUtils.TrimmedStringWithoutSpaces(@"
                V0 [ V1(2) V3(1) ]
                V1 [ V3(3) V4(10) ]
                V2 [ V0(4) V5(5) ]
                V3 [ V2(2) V4(2) V5(8) V6(4) ]
                V4 [ V6(6) ]
                V5 [ ]
                V6 [ V5(1) ]");

            // Act
            string actual = TestUtils.TrimmedStringWithoutSpaces(graph.ToString());

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#12
0
        public void Graph_07_Dijkstra_02_OnWeightedGraphFromLectureExample()
        {
            // Arrange
            IGraph graph    = DSBuilder.CreateGraphFromLectureWeightedExample();
            string expected = TestUtils.TrimmedStringWithoutSpaces(@"
                V1(0) [V2(2) V4(1)]
                V2(2) [V4(3) V5(10)]
                V3(4) [V1(4) V6(3)]
                V4(1) [V3(3) V5(2) V6(8) V7(4)]
                V5(3) [V7(6)]
                V6(6) [ ]
                V7(5) [V6(1)]");

            // Act
            graph.Dijkstra("V1");
            string actual = TestUtils.TrimmedStringWithoutSpaces(graph.ToString());

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#13
0
        public void Graph_07_Dijkstra_01_OnGraph14_1()
        {
            // Arrange
            IGraph graph    = DSBuilder.CreateGraphFromBook14_1();
            string expected = TestUtils.TrimmedStringWithoutSpaces(@"
                V0(0) [ V1(2) V3(1) ]
                V1(2) [ V3(3) V4(10) ]
                V2(3) [ V0(4) V5(5) ]
                V3(1) [ V2(2) V4(2) V5(8) V6(4) ]
                V4(3) [ V6(6) ]
                V5(6) [ ]
                V6(5) [ V5(1) ]");

            // Act
            graph.Dijkstra("V0");
            string actual = TestUtils.TrimmedStringWithoutSpaces(graph.ToString());

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#14
0
        public void Graph_06_Unweighted_01_OnUnweightedGraphFromLectureExample()
        {
            // Arrange
            IGraph graph    = DSBuilder.CreateGraphFromLectureUnweightedExample();
            string expected = TestUtils.TrimmedStringWithoutSpaces(@"
                v1(1) [ v2(1) v4(1) ]
                v2(2) [ v4(1) v5(1) ]
                v3(0) [ v1(1) v6(1) ]
                v4(2) [ v3(1) v5(1) v6(1) ]
                v5(3) [ v7(1) ]
                v6(1) [ ]
                v7(4) [ v4(1) v6(1) ]");

            // Act
            graph.Unweighted("v3");
            string actual = TestUtils.TrimmedStringWithoutSpaces(graph.ToString());

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#15
0
        public void Graph_07_Dijkstra_03_OnWeightedGraphFromLectureExersize()
        {
            // Arrange
            IGraph graph    = DSBuilder.CreateGraphFromLectureWeightedExercise();
            string expected = TestUtils.TrimmedStringWithoutSpaces(@"
                A(0) [C(2) E(8) G(6)]
                B(9) [D(7) E(2) F(4) H(4)]
                C(2) [A(2) D(3) G(2)]
                D(5) [B(7) C(3) E(2) F(3)]
                E(7) [A(8) B(2) D(2)]
                F(6) [B(4) D(3) G(2)]
                G(4) [A(6) C(2) F(2)]
                H(13) [B(4)]");

            // Act
            graph.Dijkstra("A");
            string actual = TestUtils.TrimmedStringWithoutSpaces(graph.ToString());

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#16
0
        public void Graph_03_GetVertex_01_OnEmptyGraph()
        {
            // Arrange
            // Ugly unittest. Normally we test only functionallity (so
            // we use the interfaces. Now we really want to see the
            // contents, so we use Graph instead of IGraph
            Graph  graph          = (Graph)DSBuilder.CreateGraphEmpty();
            int    expected_count = 1;
            string expected_name  = "test03";

            // Act
            Vertex v = graph.GetVertex("test03");

            // Assert
            Assert.AreEqual(expected_count, graph.vertexMap.Count);
            Assert.AreEqual(expected_name, graph.vertexMap.Last().Key);
            Assert.AreEqual(expected_name, v.GetName());
            Assert.AreEqual(Graph.INFINITY, v.GetDistance());
            Assert.IsNull(v.GetPrevious());
            Assert.IsFalse(v.GetKnown());
        }
示例#17
0
        public void Graph_06_Unweighted_02_OnUnweightedGraphFromExersize()
        {
            // Arrange
            IGraph graph    = DSBuilder.CreateGraphFromLectureUnweightedExercise();
            string expected = TestUtils.TrimmedStringWithoutSpaces(@"
                A(0) [ G(1) H(1) ]
                B(2) [ C(1) F(1) ]
                C(3) [ ]
                D(4) [ B(1) G(1) ]
                E(2) [ I(1) ]
                F(3) [ C(1) ]
                G(1) [ E(1) ]
                H(1) [ B(1) G(1) ]
                I(3) [ D(1) ]");

            // Act
            graph.Unweighted("A");
            string actual = TestUtils.TrimmedStringWithoutSpaces(graph.ToString());

            // Assert
            Assert.AreEqual(expected, actual);
        }