public void TestDeleteAt() { MyLinkedList l1 = new MyLinkedList(); l1.Insert(c2); l1.Insert(c1); l1.Insert(c3, 1); l1.Insert(c4, 0); l1.Insert(c5, 4); l1.Delete(3); l1.Delete(3); Assert.AreEqual(3, l1.Count); Assert.AreEqual("4 Kurt Nielsen 33\n2 Bjørn Borg 30\n3 Cristian Nielsen 20\n", l1.ToString()); }
public void Can_Travel_All() { var myLinkedList = new MyLinkedList <int>(); myLinkedList.AddFirst(1); myLinkedList.AddLast(2); myLinkedList.AddLast(3); var list = myLinkedList.ToList(); list[0].Should().Be(1); list[1].Should().Be(2); list[2].Should().Be(3); list.Count.Should().Be(3); }
public void TestRemove() { MyLinkedList list = new MyLinkedList(); list.Add(1); list.Add(2); list.Add(3); list.Remove(2); Assert.That(list.Length(), Is.EqualTo(2)); Assert.That(list.Get(0), Is.EqualTo(1)); Assert.That(list.Get(1), Is.EqualTo(3)); }
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 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)); }
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 }
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 }
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 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 TestInitialize() { memberList = new MyLinkedList <ClubMember>(); memberList.Append(new ClubMember { Id = 1, FirstName = "Farrand", LastName = "Semkins", Gender = Gender.Female, Age = 77 }); memberList.Append(new ClubMember { Id = 2, FirstName = "Trev", LastName = "Quail", Gender = Gender.Male, Age = 84 }); memberList.Append(new ClubMember { Id = 3, FirstName = "Dani", LastName = "Ballister", Gender = Gender.Female, Age = 76 }); memberList.Append(new ClubMember { Id = 4, FirstName = "Hyacinthie", LastName = "Mish", Gender = Gender.Female, Age = 70 }); memberList.Append(new ClubMember { Id = 5, FirstName = "Jarib", LastName = "Boustred", Gender = Gender.Male, Age = 32 }); memberList.Append(new ClubMember { Id = 6, FirstName = "Erl", LastName = "Meeson", Gender = Gender.Male, Age = 62 }); memberList.Append(new ClubMember { Id = 7, FirstName = "Aile", LastName = "Highman", Gender = Gender.Female, Age = 79 }); memberList.Append(new ClubMember { Id = 8, FirstName = "Rheta", LastName = "Battelle", Gender = Gender.Female, Age = 42 }); memberList.Append(new ClubMember { Id = 9, FirstName = "Olimpia", LastName = "Foulsham", Gender = Gender.Female, Age = 60 }); memberList.Append(new ClubMember { Id = 10, FirstName = "Dagny", LastName = "Ilchenko", Gender = Gender.Male, Age = 34 }); memberList.Append(new ClubMember { Id = 11, FirstName = "Davis", LastName = "Gilbride", Gender = Gender.Male, Age = 46 }); memberList.Append(new ClubMember { Id = 12, FirstName = "Kamillah", LastName = "Bahls", Gender = Gender.Female, Age = 24 }); memberList.Append(new ClubMember { Id = 13, FirstName = "Flore", LastName = "Ansley", Gender = Gender.Female, Age = 89 }); memberList.Append(new ClubMember { Id = 14, FirstName = "Glad", LastName = "Clowser", Gender = Gender.Female, Age = 48 }); memberList.Append(new ClubMember { Id = 15, FirstName = "Christian", LastName = "Congram", Gender = Gender.Female, Age = 33 }); memberList.Append(new ClubMember { Id = 16, FirstName = "Tore", LastName = "Saggs", Gender = Gender.Male, Age = 28 }); memberList.Append(new ClubMember { Id = 17, FirstName = "Vevay", LastName = "Klezmski", Gender = Gender.Female, Age = 43 }); memberList.Append(new ClubMember { Id = 18, FirstName = "Bren", LastName = "Merrikin", Gender = Gender.Female, Age = 46 }); memberList.Append(new ClubMember { Id = 19, FirstName = "Benoit", LastName = "Filler", Gender = Gender.Male, Age = 16 }); memberList.Append(new ClubMember { Id = 20, FirstName = "Lucien", LastName = "Bottrell", Gender = Gender.Male, Age = 41 }); memberList.Append(new ClubMember { Id = 21, FirstName = "Emmy", LastName = "Pechell", Gender = Gender.Male, Age = 61 }); memberList.Append(new ClubMember { Id = 22, FirstName = "Merle", LastName = "Bennet", Gender = Gender.Female, Age = 42 }); memberList.Append(new ClubMember { Id = 23, FirstName = "Solomon", LastName = "Sarrell", Gender = Gender.Male, Age = 61 }); memberList.Append(new ClubMember { Id = 24, FirstName = "Shurlock", LastName = "Shreenan", Gender = Gender.Male, Age = 84 }); memberList.Append(new ClubMember { Id = 25, FirstName = "Chadd", LastName = "Hanney", Gender = Gender.Male, Age = 80 }); }