static void Main() { ReversedList<int> myRList = new ReversedList<int>(12); for (int i = 0; i < 20; i++) { myRList.Add(i + 1); } myRList[8] = 99; Console.WriteLine(myRList[8]); Console.WriteLine("{0}\n", string.Join("-", myRList)); var removedElement = myRList.Remove(2); Console.WriteLine("removed -> {0}", removedElement); foreach (var num in myRList) { Console.Write("{0}-", num); } removedElement = myRList.Remove(2); Console.WriteLine("\n\nremoved -> {0}", removedElement); foreach (var num in myRList) { Console.Write("{0}-", num); } Console.Read(); }
public static void Main() { var rl = new ReversedList<int>(); // Add elements rl.Add(1); rl.Add(2); rl.Add(3); rl.Add(4); rl.Add(5); rl.Add(6); rl.Add(7); // Print elements Console.WriteLine("Print elements"); Console.WriteLine(string.Join(" ", rl)); // Remove elements rl.Remove(1); rl.Remove(3); rl.Remove(5); Console.WriteLine("After remove"); Console.WriteLine(string.Join(" ", rl)); }
public void RemoveTwiceTheSameIndex() { var list = new ReversedList <int>(); list.Add(3); list.Add(45); list.Add(23000000); list.Add(24000000); list.Add(567); list.Remove(2); list.Remove(2); Assert.AreEqual(3, list.Count, MESSAGE_NOTMATCHINGCOUNT); Assert.AreEqual(8, list.Capacity, MESSAGE_NOTMATCHINGCAPACITY); var items = new List <int>(); foreach (var item in list) { items.Add(item); } CollectionAssert.AreEqual(items, new List <int>() { 567, 24000000, 3 }, MESSAGE_NOTCORRECTITEMS); }
public void Remove() { R.Add(4); Assert.IsTrue(R.Remove(4)); Assert.IsFalse(R.Remove(10)); Assert.AreEqual(new[] { 5, 3, 2, 1, 4 }, R); }
static void Main(string[] args) { ReversedList<int> ints = new ReversedList<int>(); ints.Add(5); ints.Add(8); ints.Add(10); ints.Add(11); ints.Add(12); ints.Add(13); ints.Remove(2); ints.Remove(1); Console.WriteLine(ints[2]); }
static void Main(string[] args) { var rl = new ReversedList<int>(); rl.Add(4); rl.Add(14); rl.Add(8); rl.Add(3); rl.Add(18); rl.Add(23); rl.Add(67); rl.Add(91); rl.Remove(2); rl.Remove(2); Console.WriteLine(string.Join(" ", rl)); }
static void Main() { var testList = new ReversedList<int>(); testList.Add(1); testList.Add(2); testList.Add(3); testList.Add(4); testList.Add(5); testList.Add(6); testList.Add(7); testList.Add(8); testList.Add(9); testList.Add(10); testList.Add(11); testList.Add(12); testList.Add(13); testList.Add(14); testList.Add(15); testList.Add(16); testList.Add(17); Console.WriteLine(testList.Capacity); testList.Remove(10); Console.WriteLine(string.Join(" ", testList)); Console.WriteLine(testList[0]); }
public static void Main() { var reversedList = new ReversedList<int>(4); reversedList.Add(1); reversedList.Add(2); reversedList.Add(3); reversedList.Add(4); // current list items are [4 3 2 1] // capacity will grow twice (8) then add 5 reversedList.Add(5); // current list items are [5 4 3 2 1] Console.WriteLine("Current list"); PrintList(reversedList); reversedList.Remove(4); // remove element at index 4 -> value 1 // current list items are [5 4 3 2] Console.WriteLine("\nRemove element at index 4"); PrintList(reversedList); Console.WriteLine("\nChange value = 10 of index 1"); reversedList[1] = 10; // change value = 10 of index 1 PrintList(reversedList); Console.WriteLine("\ncount: {0}", reversedList.Count); Console.WriteLine("capacity: {0}", reversedList.Capacity); }
static void Main(string[] args) { var reversedList = new ReversedList<int>(); reversedList.Add(1); reversedList.Add(2); reversedList.Add(3); reversedList.Add(4); reversedList.Add(5); System.Console.WriteLine("Elements: " + string.Join(" ", reversedList)); System.Console.WriteLine("Element count: {0}", reversedList.Count); System.Console.WriteLine(new string('-', 20)); var removeIndex = 1; reversedList.Remove(removeIndex); System.Console.WriteLine("Elements: {0} (removed element at index {1})", string.Join(" ", reversedList), removeIndex); System.Console.WriteLine("Element count: {0}", reversedList.Count); System.Console.WriteLine(new string('-', 20)); System.Console.WriteLine("Current capacity: {0}", reversedList.Capacity); System.Console.WriteLine("Current elements count: {0}", reversedList.Count); var elementsToAdd = 20; for (int i = 0; i < elementsToAdd; i++) { reversedList.Add(i + 1); } System.Console.WriteLine("{0} elements added", elementsToAdd); System.Console.WriteLine("Current capacity: {0}", reversedList.Capacity); System.Console.WriteLine("Current elements count: {0}", reversedList.Count); System.Console.WriteLine(new string('-', 20)); var indexCheck = 20; System.Console.WriteLine("Element at index {0}: {1}", indexCheck, reversedList[indexCheck]); }
public static void Main(string[] args) { ReversedList<int> testList = new ReversedList<int>(); for (int i = 0; i < 100; i++) { testList.Add(i); } Console.WriteLine(testList[99]); Console.WriteLine(testList[0]); testList.Add(100); foreach (var number in testList) { Console.Write(number + ", "); } Console.WriteLine(); Console.WriteLine(testList.Count); testList.Remove(0); Console.WriteLine(testList.Count); }
static void Main() { var list = new ReversedList<int>(); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); list.Add(0); list.Add(1); list.Add(2); list.Add(3); list.Add(4); list.Add(5); Console.WriteLine("Count = {0}", list.Count); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); Console.WriteLine(list[3]); Console.WriteLine("--------------------"); var element = list.Remove(3); Console.WriteLine("Element to remove: " + element); Console.WriteLine("Count = {0}", list.Count); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); }
static void Main() { var testList = new ReversedList <int>(); testList.Add(1); testList.Add(2); testList.Add(3); testList.Add(4); testList.Add(5); testList.Add(6); testList.Add(7); testList.Add(8); testList.Add(9); testList.Add(10); testList.Add(11); testList.Add(12); testList.Add(13); testList.Add(14); testList.Add(15); testList.Add(16); testList.Add(17); Console.WriteLine(testList.Capacity); testList.Remove(10); Console.WriteLine(string.Join(" ", testList)); Console.WriteLine(testList[0]); }
static void Main() { var rev = new ReversedList<int>(); rev.Add(1); rev.Add(2); rev.Add(3); rev.Add(4); rev.Add(5); foreach (var item in rev) { Console.WriteLine(item); } Console.WriteLine(); Console.WriteLine("Count " + rev.Count); Console.WriteLine("Capacity " + rev.Capacity); Console.WriteLine("Element on index 0 -> " + rev[0]); Console.WriteLine("Remove element on index 0 -> " + rev.Remove(0)); Console.WriteLine("Count " + rev.Count); Console.WriteLine("Capacity " + rev.Capacity); Console.WriteLine(); rev[0] = 10; for (int i = 0; i < rev.Count; i++) { Console.WriteLine(rev[i]); } }
public void Remove_InvalidIndex_ShouldThrow() { var list = new ReversedList<int>(); list.Add(1); list.Add(101); list.Remove(2); }
public void RemoveBiggerIndexFromEmptyCollection() { var list = new ReversedList <int>(); list.Remove(1); Assert.AreEqual(0, list.Count, MESSAGE_NOTMATCHINGCOUNT); Assert.AreEqual(1, list.Capacity, MESSAGE_NOTMATCHINGCAPACITY); }
static void Main(string[] args) { Console.WriteLine(); //creates GenericList<int> ReversedList<int> list = new ReversedList<int>(); //empty list test Console.WriteLine (list); //adding test for (int i = 0; i < 10; i++) { list.Add(i); Console.WriteLine(list); } // ToString() Console.WriteLine(list); //removing element by index test for (int i = 9; i >= 0; i--) { list.Remove(i); Console.WriteLine(list); } list.Add(6); list.Add(1); list.Add(7); list.Add(5); list.Add(9); list.Add(2); list.Add(8); list.Add(0); list.Add(3); list.Add(4); // ToString() Console.WriteLine(list); //foreeach foreach (var item in list) { Console.WriteLine(item); } //count Console.WriteLine("Count: {0}",list.Count); //Capacity Console.WriteLine("Capacity: {0}",list.Capacity); }
static void Main() { Console.WriteLine(); // creates GenericList<int> ReversedList <int> list = new ReversedList <int>(); //empry list test Console.WriteLine(list); // adding test for (int i = 0; i < 10; i++) { list.Add(i); Console.WriteLine(list); } // ToString() Console.WriteLine(list); // removing element by index test for (int i = 9; i >= 0; i--) { list.Remove(i); Console.WriteLine(list); } list.Add(6); list.Add(1); list.Add(7); list.Add(5); list.Add(9); list.Add(2); list.Add(8); list.Add(0); list.Add(3); list.Add(4); // ToString() Console.WriteLine(list); // Foreach foreach (var item in list) { Console.WriteLine(item); } // Count Console.WriteLine("Count: {0}", list.Count); // Capacity Console.WriteLine("Capacity: {0}", list.Capacity); }
static void Main(string[] args) { var reversedList = new ReversedList<int>(); reversedList.Add(0); reversedList.Add(1); reversedList.Add(2); reversedList.Add(3); reversedList.Add(4); reversedList.Remove(2); Console.WriteLine(string.Join(" ", reversedList)); }
static void Main() { var list = new ReversedList<int>(2); list.Add(1); list.Add(2); list.Add(3); list.Add(4); list.Remove(2); foreach (var element in list) { Console.WriteLine(element); } }
static void Main(string[] args) { var reversedList = new ReversedList <int>(); reversedList.Add(0); reversedList.Add(1); reversedList.Add(2); reversedList.Add(3); reversedList.Add(4); reversedList.Remove(2); Console.WriteLine(string.Join(" ", reversedList)); }
public void Remove_ListOfElements_ShouldRemove() { var reversedList = new ReversedList <int> { 1, 2, 3 }; reversedList.Remove(1); var expectedAtIndexZero = 3; var expectedAtIndexOne = 1; Assert.AreEqual(expectedAtIndexZero, reversedList[0]); Assert.AreEqual(expectedAtIndexOne, reversedList[1]); }
static void Main() { ReversedList<int> collection = new ReversedList<int>(); collection.Add(1); collection.Add(2); collection.Add(3); collection.Add(4); collection.Add(5); collection.Remove(0); Console.WriteLine(collection.Count); Console.WriteLine(collection.Capacity); Console.WriteLine(string.Join(", ", collection)); }
public void RemoveIndexEqualToEnd() { var list = new ReversedList <int>(); list.Add(3); list.Add(45); list.Add(23000000); list.Add(24000000); list.Add(567); list.Remove(5); Assert.AreEqual(5, list.Count, MESSAGE_NOTMATCHINGCOUNT); Assert.AreEqual(8, list.Capacity, MESSAGE_NOTMATCHINGCAPACITY); }
static void Main(string[] args) { ReversedList<int> proba = new ReversedList<int>(); proba.Add(5); proba.Add(6); proba.Add(7); proba.Remove(1); Console.WriteLine(proba[1]); foreach (var item in proba) { Console.Write(item + " "); } }
public void RemoveBiggerIndexBetweenEndAndCapacity() { var list = new ReversedList <int>(); list.Add(3); list.Add(45); list.Add(23000000); list.Add(24000000); list.Add(567); list.Remove(6); Assert.AreEqual(5, list.Count, MESSAGE_NOTMATCHINGCOUNT); Assert.AreEqual(8, list.Capacity, MESSAGE_NOTMATCHINGCAPACITY); }
static void Main(string[] args) { ReversedList<int> test = new ReversedList<int>(); test.Add(4); test.Add(5); test.Add(1); test.Add(21); test.Remove(3); test.Add(10); test.Add(15); test[0] = 14; foreach (var num in test) { Console.WriteLine(num); } }
public static void Main() { var reversedList = new ReversedList<int>(); reversedList.Add(5); reversedList.Add(10); reversedList.Add(15); reversedList.Add(20); reversedList.Add(25); Console.WriteLine(reversedList); foreach (var num in reversedList) { Console.Write(num + ", "); } Console.WriteLine(); Console.WriteLine(reversedList[4]); Console.WriteLine(reversedList.Capacity()); Console.WriteLine(reversedList.Count()); reversedList.Remove(4); Console.WriteLine(reversedList); reversedList.Add(30); reversedList.Add(31); reversedList.Add(32); reversedList.Add(33); reversedList.Add(34); reversedList.Add(35); reversedList.Add(36); reversedList.Add(37); reversedList.Add(38); reversedList.Add(39); reversedList.Add(40); reversedList.Add(30); reversedList.Add(31); reversedList.Add(32); Console.WriteLine(reversedList); }
public static void Main() { ReversedList<int> testList = new ReversedList<int>(); //List<int> testList = new List<int>(); for (int i = 0; i < 20; i++) { testList.Add(i); } Console.WriteLine(testList); testList.Remove(3); Console.WriteLine(testList); Console.WriteLine(testList.Count); Console.ReadLine(); }
public static void Main() { ReversedList <int> testList = new ReversedList <int>(); //List<int> testList = new List<int>(); for (int i = 0; i < 20; i++) { testList.Add(i); } Console.WriteLine(testList); testList.Remove(3); Console.WriteLine(testList); Console.WriteLine(testList.Count); Console.ReadLine(); }
public void RemoveByIndexSinglePopulatedCollection() { var list = new ReversedList <int>(); list.Add(3); list.Remove(0); Assert.AreEqual(0, list.Count, MESSAGE_NOTMATCHINGCOUNT); Assert.AreEqual(1, list.Capacity, MESSAGE_NOTMATCHINGCAPACITY); var items = new List <int>(); foreach (var item in list) { items.Add(item); } CollectionAssert.AreEqual(items, new List <int>() { }, MESSAGE_NOTCORRECTITEMS); }
public static void Main(string[] arg) { ReversedList<int> revList = new ReversedList<int>() {6, 5, 4, 3, 2, 1}; revList.Add(0); Console.WriteLine("Element with index(0) is " + revList[0]); Console.WriteLine("Element with index(5) is " + revList[5]); Console.WriteLine(); Console.WriteLine("Foreach for the Reversed List:"); Console.WriteLine(); int index = 0; foreach(var item in revList) { Console.WriteLine(index + "th el : " + item + ";"); index++; } Console.WriteLine(); Console.WriteLine("List Count: {0},\nList Capacity: {1}", revList.Count, revList.Capacity); Console.WriteLine(); Console.WriteLine("Removing element with value 6 =>"); revList.Remove(6); Console.WriteLine("List Count: {0},\nList Capacity: {1}", revList.Count, revList.Capacity); }
public static void Main() { ReversedList<int> numbers = new ReversedList<int>(2); Console.WriteLine("Adding elements in the list."); for (int i = 0; i < 10; i++) { Console.WriteLine("Count = " + numbers.Count); Console.WriteLine("Capacity = " + numbers.Capacity); numbers.Add(i); } Console.WriteLine("Removing the first indexes."); while (numbers.Count > 0) { foreach (var number in numbers) { Console.Write(number + " "); } Console.WriteLine(" -> Count = " + numbers.Count); numbers.Remove(0); } }
static void Main() { var reversedList = new ReversedList<int>(); reversedList.Add(0); reversedList.Add(1); Console.WriteLine("Number of elements: {0}", reversedList.Count); reversedList.Add(2); reversedList.Add(3); Console.WriteLine("Capacity before resizing: {0}", reversedList.Capacity); reversedList.Add(4); Console.WriteLine("Capacity after adding and resizing: {0}", reversedList.Capacity); Console.WriteLine("Iterating:"); foreach (var element in reversedList) { Console.WriteLine(element); } reversedList.Remove(3); Console.WriteLine("Count after removing: {0}", reversedList.Count); Console.WriteLine("Iterating:"); foreach (var element in reversedList) { Console.WriteLine(element); } }
public static void Main() { IReversedList<int> reversedList = new ReversedList<int>(1); reversedList.Add(5); reversedList.Add(4); reversedList.Add(3); reversedList.Add(2); reversedList.Add(1); Console.WriteLine("List capacity: " + reversedList.Capacity); Console.WriteLine("Elements count: " + reversedList.Count); reversedList.Remove(4); Console.WriteLine(reversedList); Console.WriteLine("List capacity: " + reversedList.Capacity); Console.WriteLine("Elements count: " + reversedList.Count); foreach (var item in reversedList) { Console.WriteLine("item: " + item); } Console.WriteLine("Item at index 0: " + reversedList[0]); reversedList[0] = 69; Console.WriteLine("Item at index 0: " + reversedList[0]); try { reversedList[500] = 569; } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } try { var invalidList = new ReversedList<string>(-5); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } try { reversedList.Remove(5000); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } var bigReversedList = new ReversedList<int>(); for (int i = 0; i < 10000; i++) { bigReversedList.Add(i); } Console.WriteLine(string.Join(", ", bigReversedList.Take(10))); }
public void Remove_EmptyList_ShouldThrow() { var reversedList = new ReversedList <int>(); reversedList.Remove(0); }
public void Remove_ValidIndex_ShouldRemoveCorrectly() { var list = new ReversedList<int>(); list.Add(1); list.Add(2); list.Add(3); list.Add(4); list.Add(5); list.Remove(2); Assert.AreEqual(4, list.Count); CollectionAssert.AreEqual(new List<int> { 5, 4, 2, 1 }, list.ToList()); }
public static void Main(string[] args) { ConsoleKeyInfo Key; do { Console.Clear(); Console.WriteLine ("Select:"); Console.WriteLine ("1. Sum and average"); Console.WriteLine ("2. Sorting words"); Console.WriteLine ("3. Longest subsequence"); Console.WriteLine ("4. Remove odd occurences"); Console.WriteLine ("5. Count occurences"); Console.WriteLine ("6. Reversed list"); Console.WriteLine ("7. Linked list"); Console.WriteLine ("8. Calcualting distance in labyrinth."); Console.WriteLine ("q - Quit"); Key = Console.ReadKey (); Console.WriteLine(); switch (Key.KeyChar) { case '1': // Sum and avararge Console.WriteLine ("Sum and Average. Enter space separated integers: "); try { var ints = new Integers (Console.ReadLine ()); Console.WriteLine ("Sum={0:G}; Average={1:G}", ints.Sum (), ints.Avg ()); } catch (FormatException e) { Console.WriteLine (e.Message); } break; case '2': // Sort words Console.WriteLine ("Sorting words. Enter space separated words: "); { var words = new Words (Console.ReadLine ()); Console.WriteLine (words.Sort ()); } break; case '3': // Longest subsequence Console.WriteLine ("Longest subsequence. Enter space separated integers: "); try { var ints = new Integers (Console.ReadLine ()); ints.LongestSeq ().ForEach (i => Console.Write ("{0} ", i)); Console.Write ("\n"); } catch (FormatException e) { Console.WriteLine (e.Message); } break; case '4': // Remove odd occurences Console.WriteLine ("Remove odd occurences. Enter space separated integers: "); try { var ints = new Integers (Console.ReadLine ()); ints.RemoveOddOcc ().ForEach (i => Console.Write ("{0} ", i)); Console.Write ("\n"); } catch (FormatException e) { Console.WriteLine (e.Message); } break; case '5': // Count occurences Console.WriteLine ("Count occurences. Enter space separated integers between 0 and 1000: "); try { var ints = new Integers (Console.ReadLine (), 0, 1000); foreach (var pair in ints.CountOcc()) { Console.WriteLine ("{0} -> {1} times ", pair.Key, pair.Value); } } catch (FormatException e) { Console.WriteLine (e.Message); } catch (ArgumentOutOfRangeException e) { Console.WriteLine (e.Message); } break; case '6': // Reversed list Console.WriteLine ("Revered list. Adding elements 1,2,3,4 and changing index 0."); { var revList = new ReversedList<int> (); revList.Add (1); revList.Add (2); revList.Add (3); revList.Add (4); foreach (var item in revList) { Console.Write ("{0} ", item); } Console.Write ("\n"); revList.Remove (0); foreach (var item in revList) { Console.Write ("{0} ", item); } Console.Write ("\n"); revList.Add (4); foreach (var item in revList) { Console.Write ("{0} ", item); } Console.Write ("\n"); revList [0] = 44; foreach (var item in revList) { Console.Write ("{0} ", item); } Console.Write ("\n"); Console.Write (revList [0]); Console.Write ("\n"); } break; case '7': // Linked list Console.WriteLine ("Lnked list. Adding ints 1,2,3,4,2,5,6. Removing index 5, 2 and 0."); { var linkedList = new LinkedList<int> (); linkedList.Add (1); linkedList.Add (2); linkedList.Add (3); linkedList.Add (4); linkedList.Add (2); linkedList.Add (5); linkedList.Add (6); foreach (var item in linkedList) { Console.Write ("{0} ", item); } Console.Write ("\n"); linkedList.Remove (5); foreach (var item in linkedList) { Console.Write ("{0} ", item); } Console.Write ("\n"); linkedList.Remove (2); foreach (var item in linkedList) { Console.Write ("{0} ", item); } Console.Write ("\n"); linkedList.Remove (0); foreach (var item in linkedList) { Console.Write ("{0} ", item); } Console.Write ("\n"); Console.WriteLine ("Head {0}", linkedList.Head.val); Console.WriteLine ("Tail {0}", linkedList.Tail.val); Console.WriteLine ("First index of 2 is {0}", linkedList.FirstIndexOf (2)); Console.WriteLine ("Last index of 2 is {0}", linkedList.LastIndexOf (2)); } break; case '8': // Distance in labyrinth Console.WriteLine ("Calcualting distance in labyrinth."); { var map = new LabyrinthMap (new LabyrinthMap.mapItem[,] { { LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.x, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.x}, { LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.x, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.x, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.x}, { LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.x, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.x, LabyrinthMap.mapItem.o}, { LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.x, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.o}, { LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.x, LabyrinthMap.mapItem.x, LabyrinthMap.mapItem.o}, { LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.x, LabyrinthMap.mapItem.o, LabyrinthMap.mapItem.x} }); try { var start = new LabyrinthPos (1, 2); var labyrinth = new Labyrinth (map, start); labyrinth.map.Print (); var dst = labyrinth.calcDistances (); dst.MarkFreeAsU (); dst.Print (); } catch (AccessViolationException) { Console.WriteLine ("Invalid start position selected"); } } break; }// switch Console.ReadKey (); }// do while (Key.KeyChar != 'q'); }
public void RemoveIndexEqualToEnd() { var list = new ReversedList<int>(); list.Add(3); list.Add(45); list.Add(23000000); list.Add(24000000); list.Add(567); list.Remove(5); Assert.AreEqual(5, list.Count, MESSAGE_NOTMATCHINGCOUNT); Assert.AreEqual(8, list.Capacity, MESSAGE_NOTMATCHINGCAPACITY); }
public void RemoveTwiceTheSameIndex() { var list = new ReversedList<int>(); list.Add(3); list.Add(45); list.Add(23000000); list.Add(24000000); list.Add(567); list.Remove(2); list.Remove(2); Assert.AreEqual(3, list.Count, MESSAGE_NOTMATCHINGCOUNT); Assert.AreEqual(8, list.Capacity, MESSAGE_NOTMATCHINGCAPACITY); var items = new List<int>(); foreach (var item in list) { items.Add(item); } CollectionAssert.AreEqual(items, new List<int>() { 567, 24000000, 3 }, MESSAGE_NOTCORRECTITEMS); }
public void RemoveBiggerIndexBetweenEndAndCapacity() { var list = new ReversedList<int>(); list.Add(3); list.Add(45); list.Add(23000000); list.Add(24000000); list.Add(567); list.Remove(6); Assert.AreEqual(5, list.Count, MESSAGE_NOTMATCHINGCOUNT); Assert.AreEqual(8, list.Capacity, MESSAGE_NOTMATCHINGCAPACITY); }
public void RemoveZeroIndexFromEmptyCollection() { var list = new ReversedList<int>(); list.Remove(0); Assert.AreEqual(0, list.Count, MESSAGE_NOTMATCHINGCOUNT); Assert.AreEqual(1, list.Capacity, MESSAGE_NOTMATCHINGCAPACITY); }
public static void Main() { Console.WriteLine("Creation of ReversedList with initial values: "); ReversedList<int> list = new ReversedList<int>(new int[] { 1, 2, 3, 4 }); Console.WriteLine("Capacity: " + list.Capacity); Console.WriteLine("Count: " + list.Count); Console.WriteLine("Elements: {0}", string.Join(", ", list)); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Press any key for next demo...."); Console.ReadKey(); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Creation of blank ReversedList with initial capacity of 3"); Console.WriteLine("------------------------------------------------------------"); list = new ReversedList<int>(3); Console.WriteLine("Capacity: " + list.Capacity); Console.WriteLine("Count: " + list.Count); Console.WriteLine("Elements: {0}", list.Count == 0 ? "(no elements)" : string.Join(", ", list)); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Press any key for next demo...."); Console.ReadKey(); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Add elelments (1, 2, 3) to blank ReversedList of size 3"); Console.WriteLine("------------------------------------------------------------"); list = new ReversedList<int>(3); list.Add(1); list.Add(2); list.Add(3); Console.WriteLine("Capacity: " + list.Capacity); Console.WriteLine("Count: " + list.Count); Console.WriteLine("Elements: {0}", list.Count == 0 ? "(no elements)" : string.Join(", ", list)); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Press any key for next demo...."); Console.ReadKey(); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Add one additional elelment (10) to above ReversedList -> double capacity"); Console.WriteLine("------------------------------------------------------------"); list.Add(10); Console.WriteLine("Capacity: " + list.Capacity); Console.WriteLine("Count: " + list.Count); Console.WriteLine("Elements: {0}", list.Count == 0 ? "(no elements)" : string.Join(", ", list)); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Press any key for next demo...."); Console.ReadKey(); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Remove element from 2nd index from above ReversedList"); Console.WriteLine("------------------------------------------------------------"); var removed = list.Remove(2); Console.WriteLine("Capacity: " + list.Capacity); Console.WriteLine("Count: " + list.Count); Console.WriteLine("Element removed: {0}", removed); Console.WriteLine("Elements: {0}", list.Count == 0 ? "(no elements)" : string.Join(", ", list)); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Press any key for next demo...."); Console.ReadKey(); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Show elements with indexes -> Enumerator + indexes"); Console.WriteLine("------------------------------------------------------------"); for (int i = 0; i < list.Count; i++) { Console.WriteLine("Index: {0} -> {1}", i, list[i]); } }