public void AddAt_AddToMiddleOfList_CountIncreases() { // arrange CustomList <int> testList = new CustomList <int>(); int expected = 4; int actual; // act testList.Add(2); testList.Add(3); testList.Add(4); testList.AddAt(1, 1); actual = testList.Count; // assert Assert.AreEqual(expected, actual); }
public void AddAt_AddToMiddleOfList_LastIndexIsAdded() { // arrange CustomList <int> testList = new CustomList <int>(); int expected = 3; int actual; // act testList.Add(2); testList.Add(3); testList.Add(4); testList.AddAt(1, 1); actual = testList[2]; // assert Assert.AreEqual(expected, actual); }
public void AddAt_AddToStartList_IndexZeroIsAdded() { // arrange CustomList <int> testList = new CustomList <int>(); int expected = 1; int actual; // act testList.Add(2); testList.Add(3); testList.Add(4); testList.AddAt(1, 0); actual = testList[0]; // assert Assert.AreEqual(expected, actual); }
public void BinarySearch_InsertItem_ReturnsCorrectIndex() { CustomList <string> testList = new CustomList <string>() { "Computer", "Zebra", "Apple", "Demon", "Lizard", "Rock", "Seltzer", "Boron", "King", "Jack", "Pumpkin", "Quite", "Velociraptor", "Walleye", "Xenu" }; int expected = 4; testList.Sort <string>(0, testList.Count); int index = testList.BinarySearch <string>("Error"); testList.AddAt("Error", index); int actual = testList.IndexOf("Error"); Assert.AreEqual(expected, actual); }
public void BinarySearch_FindSpotAndInsertManyItems_ReturnsCorrectIndex() { CustomList <int> expected = new CustomList <int>(); for (int i = 1; i <= 100; i++) { expected.Add(i); } CustomList <int> testList = new CustomList <int>(); for (int i = 1; i <= 100; i++) { if (i % 2 != 0) { testList.Add(i); } } CustomList <int> testList2 = new CustomList <int>(); for (int i = 1; i <= 100; i++) { if (i % 2 == 0) { testList2.Add(i); } } for (int i = 0; i < testList2.Count; i++) { int index = testList.BinarySearch <int>(testList2[i]); testList.AddAt(testList2[i], index); } for (int i = 0; i < expected.Count; i++) { Assert.AreEqual(expected[i], testList[i]); } }
public void BinarySearch_InsertItemLong_ReturnsCorrectIndex() { CustomList <int> testList = new CustomList <int>(); for (int i = 1; i < 100; i++) { if (i % 2 != 0) { testList.Add(i); } } int expected = 1; int index = testList.BinarySearch <int>(2); testList.AddAt(2, index); int actual = testList.IndexOf(2); Assert.AreEqual(expected, actual); }