public void TestGenericIEnumerable()
        {
            MyLinkedList <ClubMember> list = new MyLinkedList <ClubMember>();

            list.Insert(p3);  // p3
            list.Insert(p22); // p3,p22
            list.Insert(p9);  // p9,p3,p22
            list.Insert(p1);  // p1,p9,p3,p22
            list.Append(p24); // p1,p9,p3,p22,p24
            list.Append(p5);  // p5,p1,p9,p3,p22,p24
            list.Append(p16); // p5,p1,p9,p3,p22,p24,p16

            int i = 0;

            foreach (ClubMember li in list)
            {
                Assert.AreEqual(list.ItemAt(i++), li);
            }
            Assert.AreEqual(list.Count, i);

            int j = 0;
            var e = list.GetEnumerator();

            e.Reset();
            while (e.MoveNext())
            {
                Assert.AreEqual(list.ItemAt(j++), e.Current);
            }
        }
        public void TestGenericMixedInsertsAndRemoves()
        {
            MyLinkedList <ClubMember> list = new MyLinkedList <ClubMember>();

            list.Insert(p3);             // p3
            list.Append(p22);            // p3,p22
            list.Insert(p9);             // p9,p3,p22
            list.Delete(0);              // p3,p22
            list.Insert(p1);             // p1,p3,p22
            list.Append(p24);            // p1,p3,p22,p24
            list.Insert(p5);             // p5,p1,p3,p22,p24
            list.Delete(4);              // p5,p1,p3,p22
            list.Append(p16);            // p5,p1,p3,p22,p16
            list.Delete(2);              // p5,p1,p22,p16

            Assert.AreEqual(p5, list.First);
            Assert.AreEqual(p16, list.Last);
            Assert.AreEqual(4, list.Count);

            Assert.AreEqual(p5, list.ItemAt(0));
            Assert.AreEqual(p1, list.ItemAt(1));
            Assert.AreEqual(p22, list.ItemAt(2));
            Assert.AreEqual(p16, list.ItemAt(3));
            Assert.AreEqual("5: Jarib Boustred (Male, 32 years)\n1: Farrand Semkins (Female, 77 years)\n22: Merle Bennet (Female, 42 years)\n16: Tore Saggs (Male, 28 years)\n", list.ToString());
        }
Ejemplo n.º 3
0
        public void TestItemAt()
        {
            MyLinkedList l1 = new MyLinkedList();

            l1.Insert(c2);
            l1.Insert(c1);
            Assert.AreEqual(c2, l1.ItemAt(0));
            Assert.AreEqual(c1, l1.ItemAt(1));
            Assert.AreEqual("2 Bjørn Borg 30\n1 Anders And 15\n", l1.ToString());
        }
        public void TestGenericAppend()
        {
            MyLinkedList <ClubMember> list = new MyLinkedList <ClubMember>();

            list.Append(p1);              // p1
            list.Append(p7);              // p1,p7
            list.Append(p13);             // p1,p7,p13

            Assert.AreEqual(p1, list.First);
            Assert.AreEqual(p13, list.Last);
            Assert.AreEqual(3, list.Count);

            Assert.AreEqual(p1, list.ItemAt(0));
            Assert.AreEqual(p7, list.ItemAt(1));
            Assert.AreEqual(p13, list.ItemAt(2));
        }
        public void TestGenericRemoves()
        {
            MyLinkedList <ClubMember> list = new MyLinkedList <ClubMember>();

            list.Insert(p5);              // p5
            list.Insert(p21);             // p21,p5
            list.Insert(p9);              // p9,p21,p5
            list.Insert(p24);             // p24,p9,p21,p5
            list.Delete(2);               // p24,p9,p5

            Assert.AreEqual(p24, list.First);
            Assert.AreEqual(p5, list.Last);
            Assert.AreEqual(3, list.Count);

            Assert.AreEqual(p24, list.ItemAt(0));
            Assert.AreEqual(p9, list.ItemAt(1));
            Assert.AreEqual(p5, list.ItemAt(2));
        }
        public void TestGenericListOnDecimal()
        {
            // ** decimal list test ***********
            MyLinkedList <decimal> listDecimal = new MyLinkedList <decimal>();

            // Insert decimals and test
            listDecimal.Append(3.1415m);             // Pi
            listDecimal.Append(1.4142m);             // square root of 2
            listDecimal.Append(2.7182m);             // e (Euler)
            listDecimal.Append(1.6180m);             // Golden ratio

            Assert.AreEqual(3.1415m, listDecimal.First);
            Assert.AreEqual(1.6180m, listDecimal.Last);
            Assert.AreEqual(4, listDecimal.Count);
            Assert.AreEqual(3.1415m, listDecimal.ItemAt(0));
            Assert.AreEqual(1.4142m, listDecimal.ItemAt(1));
            Assert.AreEqual(2.7182m, listDecimal.ItemAt(2));
            Assert.AreEqual(1.6180m, listDecimal.ItemAt(3));
        }
        public void TestGenericListOnString()
        {
            // ** string list test **********
            MyLinkedList <string> listString = new MyLinkedList <string>();

            // Insert strings and test
            listString.Append("Hello World!");
            listString.Append("This is a ");
            listString.Append("test of ");
            listString.Append("MyLinkedList<string>");

            Assert.AreEqual("Hello World!", listString.First);
            Assert.AreEqual("MyLinkedList<string>", listString.Last);
            Assert.AreEqual(4, listString.Count);
            Assert.AreEqual("Hello World!", listString.ItemAt(0));
            Assert.AreEqual("This is a ", listString.ItemAt(1));
            Assert.AreEqual("test of ", listString.ItemAt(2));
            Assert.AreEqual("MyLinkedList<string>", listString.ItemAt(3));
        }
        public void TestGenericListOnInt()
        {
            // ** int list test *********
            MyLinkedList <int> listInt = new MyLinkedList <int>();

            // Test for empty int list
            Assert.AreEqual(0, listInt.First);
            Assert.AreEqual(0, listInt.Last);
            Assert.AreEqual(0, listInt.Count);

            // Insert ints and test
            listInt.Append(105);
            listInt.Append(45);
            listInt.Append(11);
            listInt.Append(3);

            Assert.AreEqual(105, listInt.First);
            Assert.AreEqual(3, listInt.Last);
            Assert.AreEqual(4, listInt.Count);
            Assert.AreEqual(105, listInt.ItemAt(0));
            Assert.AreEqual(45, listInt.ItemAt(1));
            Assert.AreEqual(11, listInt.ItemAt(2));
            Assert.AreEqual(3, listInt.ItemAt(3));
        }
        public void TestSortClubMembersAfterGenderAndLastName()
        {
            MyLinkedList <ClubMember> list = new MyLinkedList <ClubMember>();

            list.Insert(p2);  // Gender : Male,   LastName : Quail
            list.Insert(p4);  // Gender : Female, LastName : Mish
            list.Insert(p23); // Gender : Male,   LastName : Sarrell
            list.Insert(p9);  // Gender : Female, LastName : Foulsham
            list.Insert(p5);  // Gender : Male,   LastName : Boustred
            list.Insert(p19); // Gender : Male,   LastName : Filler
            list.Insert(p13); // Gender : Female, LastName : Ansley

            list.Sort(new ClubMember.SortClubMembersAfterGenderAndLastName());

            Assert.AreEqual(p5, list.ItemAt(0));  // Gender : Male,   LastName : Boustred
            Assert.AreEqual(p19, list.ItemAt(1)); // Gender : Male,   LastName : Filler
            Assert.AreEqual(p2, list.ItemAt(2));  // Gender : Male,   LastName : Quail
            Assert.AreEqual(p23, list.ItemAt(3)); // Gender : Male,   LastName : Sarrell
            Assert.AreEqual(p13, list.ItemAt(4)); // Gender : Female, LastName : Ansley
            Assert.AreEqual(p9, list.ItemAt(5));  // Gender : Female, LastName : Foulsham
            Assert.AreEqual(p4, list.ItemAt(6));  // Gender : Female, LastName : Mish
        }
Ejemplo n.º 10
0
        public void TestBubbleSortInt()
        {
            MyLinkedList <int> list = new MyLinkedList <int>();

            list.Insert(55);              // 55
            list.Insert(78);              // 78, 55
            list.Insert(23);              // 23, 78, 55
            list.Insert(88);              // 88, 23, 78, 55
            list.Insert(62);              // 62, 88, 23, 78, 55
            list.Insert(49);              // 49, 62, 88, 23, 78, 55

            list.Sort();

            Assert.AreEqual(23, list.ItemAt(0));
            Assert.AreEqual(49, list.ItemAt(1));
            Assert.AreEqual(55, list.ItemAt(2));
            Assert.AreEqual(62, list.ItemAt(3));
            Assert.AreEqual(78, list.ItemAt(4));
            Assert.AreEqual(88, list.ItemAt(5));
        }
        public void TestBubbleSortClubMember()
        {
            MyLinkedList <ClubMember> list = new MyLinkedList <ClubMember>();

            list.Insert(p4);  // p4
            list.Insert(p9);  // p9, p4
            list.Insert(p5);  // p5, p9, p4
            list.Insert(p19); // p19, p5, p9, p4
            list.Insert(p23); // p23, p19, p5, p9, p4
            list.Insert(p2);  // p2, p23, p19, p5, p9, p4

            list.Sort();      // Sort on FirstName

            Assert.AreEqual(p19, list.ItemAt(0));
            Assert.AreEqual(p4, list.ItemAt(1));
            Assert.AreEqual(p5, list.ItemAt(2));
            Assert.AreEqual(p9, list.ItemAt(3));
            Assert.AreEqual(p23, list.ItemAt(4));
            Assert.AreEqual(p2, list.ItemAt(5));
        }
Ejemplo n.º 12
0
        public void TestGenericMixedInserts()
        {
            MyLinkedList <ClubMember> list = new MyLinkedList <ClubMember>();

            list.Insert(p3);             // p3
            list.Append(p22);            // p3,p22
            list.Insert(p9);             // p9,p3,p22
            list.Insert(p1);             // p1,p9,p3,p22
            list.Append(p24);            // p1,p9,p3,p22,p24
            list.Insert(p5);             // p5,p1,p9,p3,p22,p24
            list.Append(p16);            // p5,p1,p9,p3,p22,p24,p16

            Assert.AreEqual(p5, list.First);
            Assert.AreEqual(p16, list.Last);
            Assert.AreEqual(7, list.Count);

            Assert.AreEqual(p5, list.ItemAt(0));
            Assert.AreEqual(p1, list.ItemAt(1));
            Assert.AreEqual(p9, list.ItemAt(2));
            Assert.AreEqual(p3, list.ItemAt(3));
            Assert.AreEqual(p22, list.ItemAt(4));
            Assert.AreEqual(p24, list.ItemAt(5));
            Assert.AreEqual(p16, list.ItemAt(6));
        }
        public void TestSortClubMembersAfterLastName()
        {
            MyLinkedList <ClubMember> list = new MyLinkedList <ClubMember>();

            list.Insert(p2);  // LastName : Quail
            list.Insert(p4);  // LastName : Mish
            list.Insert(p23); // LastName : Sarrell
            list.Insert(p9);  // LastName : Foulsham
            list.Insert(p5);  // LastName : Boustred
            list.Insert(p19); // LastName : Filler


            list.Sort(new ClubMember.SortClubMembersAfterLastName()); // Sort on LastName

            Assert.AreEqual(p5, list.ItemAt(0));                      // LastName : Boustred
            Assert.AreEqual(p19, list.ItemAt(1));                     // LastName : Filler
            Assert.AreEqual(p9, list.ItemAt(2));                      // LastName : Foulsham
            Assert.AreEqual(p4, list.ItemAt(3));                      // LastName : Mish
            Assert.AreEqual(p2, list.ItemAt(4));                      // LastName : Quail
            Assert.AreEqual(p23, list.ItemAt(5));                     // LastName : Sarrell
        }