static void Main() { var list = new DoublyLinkedList <int>(); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); list.AddLast(5); list.AddFirst(3); list.AddFirst(2); list.AddLast(10); Console.WriteLine("Count = {0}", list.Count); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); list.RemoveFirst(); list.RemoveLast(); list.RemoveFirst(); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); list.RemoveLast(); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); }
public void RemoveLast_SeveralElements_ShouldRemoveElementsCorrectly() { // Arrange var list = new DoublyLinkedList <int>(); list.AddFirst(10); list.AddFirst(9); list.AddFirst(8); // Act var element = list.RemoveLast(); // Assert Assert.AreEqual(10, element); Assert.AreEqual(2, list.Count); var items = new List <int>(); list.ForEach(items.Add); Console.WriteLine(items[0] + items[1]); CollectionAssert.AreEqual(items, new List <int>() { 8, 9 }); }
public static void Main() { var list = new DoublyLinkedList<int>(); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); list.AddLast(5); list.AddFirst(3); list.AddFirst(2); list.AddLast(10); Console.WriteLine("Count = {0}", list.Count); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); list.RemoveFirst(); list.RemoveLast(); list.RemoveFirst(); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); list.RemoveLast(); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); }
public void AddFirstTest() { DoublyLinkedList <int> dll = new DoublyLinkedList <int>(); dll.AddFirst(10); dll.AddFirst(20); Assert.AreEqual(20, dll.Head.Value); }
public void AddFirstTest() { var list = new DoublyLinkedList<int>(); list.AddFirst(2); list.AddFirst(4); list.AddFirst(6); Assert.AreEqual(list.Head.Value, 6); Assert.AreEqual(list.Tail.Value, 2); }
public void List_CorrectlyAddsElement_UsingAddFirst() { var doubly = new DoublyLinkedList <int>(); doubly.AddFirst(100); doubly.AddFirst(200); Assert.Equal(200, doubly.HeadNode.Value); Assert.Equal(100, doubly.TailNode.Value); Assert.Equal(2, doubly.Size); }
public void AddFirst_and_AddLast_OneItem_CorrectState() { _list.AddFirst(1); Assert.AreEqual(1, _list.Count); Assert.IsFalse(_list.IsEmpty); Assert.AreSame(_list.Head, _list.Tail); _list.AddLast(5); _list.AddFirst(2); Assert.AreEqual(3, _list.Count); }
public static void Main() { var list = new DoublyLinkedList <int>(); list.AddFirst(10); list.AddFirst(7); list.AddFirst(33); Console.WriteLine(list.RemoveFirst()); list.ForEach(Console.WriteLine); }
public void AddFirst3Reverse() { string expected = "1/2/3/"; DoublyLinkedList testList = new DoublyLinkedList(); testList.AddFirst("1"); testList.AddFirst("2"); testList.AddFirst("3"); string actual = testList.ReverseShow(); Assert.AreEqual(expected, actual); }
public void Clear() { DoublyLinkedList <int> dll = new DoublyLinkedList <int>(); dll.AddFirst(new DoublyLinkedListNode <int>(10)); dll.AddFirst(new DoublyLinkedListNode <int>(20)); dll.AddLast(new DoublyLinkedListNode <int>(30)); dll.AddLast(new DoublyLinkedListNode <int>(40)); dll.Clear(); Assert.AreEqual(dll.Count, 0); }
public void AddFirst() { DoublyLinkedList <int> dll = new DoublyLinkedList <int>(); dll.AddFirst(new DoublyLinkedListNode <int>(10)); dll.AddFirst(new DoublyLinkedListNode <int>(20)); dll.AddFirst(new DoublyLinkedListNode <int>(30)); //30 <-> 20 <-> 10 : Head 20, Tail 10 Assert.AreEqual(dll.Head.Value, 30); Assert.AreEqual(dll.Head.Next.Value, 20); Assert.AreEqual(dll.Tail.Value, 10); Assert.AreEqual(dll.Tail.Previous.Value, 20); }
public void Add() { var list = new DoublyLinkedList<int>(2); list.AddFirst(1); list.AddLast(3); list.AddFirst(0); list.AddLast(4); for (var i = 0; i < 5; i++) { Assert.AreEqual(i, list[i].Value); } }
public void InitializeListFromIEnumeraable() { var list = new DoublyLinkedList <int>(); int itemCount = 1000; for (int i = 0; i < itemCount; i++) { list.AddFirst(i); } var list2 = new DoublyLinkedList <int>(list); if (list.Count != list2.Count) { Assert.Fail(); } foreach (var item in list) { if (item != list2.First.Value) { Assert.Fail(); } list2.RemoveFirst(); } Assert.IsTrue(list.Count == itemCount && list2.Count == 0); }
public void AddFirstForAllElementsAndCheckForOrder() { var list = new DoublyLinkedList <int>(); int itemCount = 1000; for (int i = 0; i < itemCount; i++) { list.AddFirst(i); } int previous = itemCount; int numberOfElementsInList = 0; foreach (var item in list) { if (previous < item) { Assert.Fail(); } previous = item; numberOfElementsInList++; } Assert.IsTrue(list.Count == itemCount && numberOfElementsInList == list.Count); }
void AddList(IReadOnlyList <int> collection, IReadOnlyList <int> items, bool reversed, bool isMutated, IReadOnlyList <int> expected) { // Arrange var left = new DoublyLinkedList <int>(collection); var version = left.Version; var right = new DoublyLinkedList <int>(items); // Act left.AddFirst(right, reversed); // Assert if (isMutated) { left.Version.Must().BeNotEqualTo(version); } else { left.Version.Must().BeEqualTo(version); } left.EnumerateForward().Must() .BeEnumerableOf <int>() .BeEqualTo(expected); left.EnumerateReversed().Must() .BeEnumerableOf <int>() .BeEqualTo(expected.Reverse()); }
public void AddFirstTest(int val, int[] expected) { list = new DoublyLinkedList(new int[] { 0, 1, 2, 3 }); list.AddFirst(val); int[] actual = list.ToArray(); Assert.AreEqual(expected, actual); }
public void AddFirst_WhenCalled_ShouldAddNodeWithGivenValueToHeadOfLinkedList(int range, int value) { // Arrange for (var i = 0; i < range; i++) { _list.Add(i); } var prevSize = _list.Size; var next = _list.Size == 0 ? null : _list.Get(0); // Act _list.AddFirst(value); // Assert var result = _list.Get(0); Assert.That( result, Is.Not.Null .And.Property(nameof(DoublyLinkedList <int> .Node.Value)).EqualTo(value)); Assert.That(result.Prev, Is.Null); Assert.That(result.Next, Is.EqualTo(next)); Assert.That(next?.Prev, Is.EqualTo(_list.Size == 1 ? null : result)); Assert.That(_list.Size, Is.EqualTo(prevSize + 1)); Assert.That(_list.Head, Is.EqualTo(result)); }
public void AddFirstArrayTest(int[] original, int[] values, int[] expected) { DoublyLinkedList sList = new DoublyLinkedList(original); sList.AddFirst(values); Assert.AreEqual(expected, sList.ToArray()); }
public void AddFirstPUT([PexAssumeUnderTest] IList <int> values, int toAddValue) { DoublyLinkedList <int> dll = new DoublyLinkedList <int>(values); dll.AddFirst(toAddValue); PexAssert.AreEqual(toAddValue, dll.Head.Value); }
public static void Main(string[] args) { DoublyLinkedList <int> doublyLinkedList = new DoublyLinkedList <int>(); SinglyLinkedList <int> singlyLinkedList = new SinglyLinkedList <int>(); Console.WriteLine($"DoublyLinkedList.IsEmpty() == {doublyLinkedList.IsEmpty()}"); doublyLinkedList.AddFirst(5); doublyLinkedList.AddFirst(20); doublyLinkedList.AddLast(25); doublyLinkedList.AddLast(41); Console.WriteLine($"DoublyLinkedList.First() == {doublyLinkedList.First()}"); Console.WriteLine($"DoublyLinkedList.Last() == {doublyLinkedList.Last()}"); Console.WriteLine($"DoublyLinkedList.Size() == {doublyLinkedList.Size()}"); Console.WriteLine($"DoublyLinkedList.IsEmpty() == {doublyLinkedList.IsEmpty()}"); // Output // ---------------- // True // 20 // 41 // 4 // False Console.WriteLine(""); Console.WriteLine($"SinglyLinkedList.IsEmpty() == {singlyLinkedList.IsEmpty()}"); singlyLinkedList.Add(2); singlyLinkedList.Add(9); singlyLinkedList.AddLast(21); singlyLinkedList.AddLast(35); Console.WriteLine($"SinglyLinkedList.First() == {singlyLinkedList.First()}"); Console.WriteLine($"SinglyLinkedList.Last() == {singlyLinkedList.Last()}"); Console.WriteLine($"SinglyLinkedList.Size() == {singlyLinkedList.Size()}"); Console.WriteLine($"SinglyLinkedList.IsEmpty() == {singlyLinkedList.IsEmpty()}"); // Output // ---------------- // True // 9 // 35 // 4 // False }
public void AddFirst_SeveralElements() { var list = new DoublyLinkedList <int>(); list.AddFirst(10); list.AddFirst(5); list.AddFirst(3); Assert.AreEqual(3, list.Count); var items = new List <int>(); list.ForEach(items.Add); CollectionAssert.AreEqual(items, new List <int> { 3, 5, 10 }); }
static void Main() { var list = new DoublyLinkedList <int>(); list.AddFirst(10); list.AddFirst(30); list.AddLast(50); list.AddLast(70); list.RemoveFirst(); foreach (var el in list) { Console.WriteLine(el); } list.RemoveFirst(); }
public void CanAddFirst() { DoublyLinkedList <int> doublyLinkedList = new DoublyLinkedList <int>(5); doublyLinkedList.AddFirst(7); Assert.AreEqual(7, doublyLinkedList.First.Value); }
public void InsertAfter() { IDoublyLinkedList <int> list = new DoublyLinkedList <int>(); list.AddFirst(new DoublyLinkedListNode <int>(22)); list.AddAfter(22, new DoublyLinkedListNode <int>(1)); Assert.AreEqual(list.FindLastNode().Value, 1); }
public void AddFirstTest() { var list = new DoublyLinkedList <int>(); list.AddFirst(1); Assert.IsTrue(list.First == list.Last, "Incorrectly added node"); }
public void AddFirst_SeveralElements_ShouldAddElementsCorrectly() { // Arrange var list = new DoublyLinkedList<int>(); // Act list.AddFirst(10); list.AddFirst(5); list.AddFirst(3); // Assert Assert.AreEqual(3, list.Count); var items = new List<int>(); list.ForEach(items.Add); CollectionAssert.AreEqual(items, new List<int>() { 3, 5, 10 }); }
public void AddFirst_SeveralElements_ShouldAddElementsCorrectly() { // Arrange var list = new DoublyLinkedList<int>(); // Act list.AddFirst(10); list.AddFirst(5); list.AddFirst(3); // Assert Assert.AreEqual(3, list.Count); var items = new List<int>(); list.ForEach(items.Add); CollectionAssert.AreEqual(items, new List<int>() { 3, 5, 10 }); }
public void AddFirst_ShouldWork() { list.AddFirst(3); Assert.Equal(1, list.Size()); list.AddFirst(5); Assert.Equal(2, list.Size()); }
public void RemoveHeadTail() { DoublyLinkedList <int> dll = new DoublyLinkedList <int>(); dll.AddFirst(new DoublyLinkedListNode <int>(10)); dll.AddFirst(new DoublyLinkedListNode <int>(20)); //20 <-> 10 Head 20, Tail 10 dll.Remove(10); // 20 <-> 30 <-> 40 : Head 10, Tail 40 Assert.AreEqual(dll.Head.Value, 20); dll.Remove(20); Assert.AreEqual(dll.Count, 0); }
public void RemoveFirst() { DoublyLinkedList <int> dll = new DoublyLinkedList <int>(); dll.AddFirst(new DoublyLinkedListNode <int>(10)); dll.AddFirst(new DoublyLinkedListNode <int>(20)); dll.AddLast(new DoublyLinkedListNode <int>(30)); dll.AddLast(new DoublyLinkedListNode <int>(40)); //20 <-> 10 <-> 30 <-> 40 : Head 20, Tail 40 dll.RemoveFirst(); // 10 <-> 30 <-> 40 : Head 10, Tail 40 Assert.AreEqual(dll.Head.Value, 10); Assert.AreEqual(dll.Head.Next.Value, 30); Assert.AreEqual(dll.Tail.Value, 40); Assert.AreEqual(dll.Tail.Previous.Value, 30); }
public void Contains() { DoublyLinkedList <int> dll = new DoublyLinkedList <int>(); dll.AddFirst(new DoublyLinkedListNode <int>(10)); dll.AddFirst(new DoublyLinkedListNode <int>(20)); dll.AddLast(new DoublyLinkedListNode <int>(30)); dll.AddLast(new DoublyLinkedListNode <int>(40)); //20 <-> 10 <-> 30 <-> 40 : Head 20, Tail 40 Assert.AreEqual(dll.Contains(10), true); Assert.AreEqual(dll.Contains(20), true); Assert.AreEqual(dll.Contains(30), true); Assert.AreEqual(dll.Contains(40), true); Assert.AreEqual(dll.Contains(100), false); }
public void Add_First_Item_Test() { int expectedCount = 6; DoublyLinkedList <int> list = InitLinkedList(); list.AddFirst(0); Assert.IsTrue(list.Count == expectedCount); Assert.IsTrue(list.Head.Value == 0); }
public void AddAfterTest() { var list = new DoublyLinkedList <int>(); var node = list.AddFirst(1); node = list.AddAfter(node, 2); node = list.AddAfter(node, 3); Assert.IsTrue(list.Last.Value == 3, "Incorrectly added node"); }
public void FindFirstTest() { var list = new DoublyLinkedList <int>(); var node = list.AddFirst(1); node = list.AddAfter(node, 2); node = list.FindFirst(2); Assert.IsTrue(node != null, "Node find incorrect"); }
static void Main(string[] args) { try { DoublyLinkedList<Person> list = new DoublyLinkedList<Person>(); list.AddFirst(new Person("Nikita Vasilyev", 24)); list.AddFirst(new Person("Bill Gates", 59)); list.AddFirst(new Person("Muhhamed Ali", 76)); list.AddLast(new Person("Lennox Lewis", 46)); list.InsertAt(new Person("Steve Jobs", 54), 2); list.Show(); list.RemoveAt(4); Console.WriteLine(list[2]); Person p = new Person("Nikita Vasilyev", 24); Console.WriteLine(list.Find(p)); list.FindLast(p).FullName = "Nikita V. Vasilyev"; list.ShowReverse(); list.Show(); } catch (IndexOutOfRangeException ex) { Console.WriteLine("Message:\t" + ex.Message); Console.WriteLine("Method:\t\t" + ex.TargetSite); } catch (ArgumentNullException ex) { Console.WriteLine("Message:\t" + ex.Message); Console.WriteLine("Method:\t\t" + ex.TargetSite); } catch (InvalidOperationException ex) { Console.WriteLine("Message:\t" + ex.Message); Console.WriteLine("Method:\t\t" + ex.TargetSite); } catch (Exception ex) { Console.WriteLine("Message:\t" + ex.Message); Console.WriteLine("Method:\t\t" + ex.TargetSite); } }
public void AddFirst_EmptyList_ShouldAddElement() { // Arrange var list = new DoublyLinkedList<int>(); // Act list.AddFirst(5); // Assert Assert.AreEqual(1, list.Count); var items = new List<int>(); list.ForEach(items.Add); CollectionAssert.AreEqual(items, new List<int>(){ 5 }); }
public void RemoveLast_OneElement_ShouldMakeListEmpty() { // Arrange var list = new DoublyLinkedList<int>(); list.AddFirst(5); // Act var element = list.RemoveLast(); // Assert Assert.AreEqual(5, element); Assert.AreEqual(0, list.Count); var items = new List<int>(); list.ForEach(items.Add); CollectionAssert.AreEqual(items, new List<int>() { }); }
public void AddFirstTest() { DoublyLinkedList<int> dll = new DoublyLinkedList<int>(); dll.AddFirst(10); dll.AddFirst(20); Assert.AreEqual(20, dll.Head.Value); }
public void Traverse() { var list = new DoublyLinkedList<int>(new[] { 1, 2, 3 }); // Perform various operations list.AddFirst(0); list.RemoveFirst(); list.AddLast(0); list.RemoveLast(); list.Insert(1, 0); list.RemoveAt(1); var current = list.First; while (current.Next != null) { current = current.Next; } Assert.AreEqual(list.Last, current); while (current.Previous != null) { current = current.Previous; } Assert.AreEqual(list.First, current); }
public void RemoveLast_SeveralElements_ShouldRemoveElementsCorrectly() { // Arrange var list = new DoublyLinkedList<int>(); list.AddFirst(10); list.AddFirst(9); list.AddFirst(8); // Act var element = list.RemoveLast(); // Assert Assert.AreEqual(10, element); Assert.AreEqual(2, list.Count); var items = new List<int>(); list.ForEach(items.Add); CollectionAssert.AreEqual(items, new List<int>() { 8, 9 }); }
public void AddFirstPUT([PexAssumeUnderTest]IList<int> values, int toAddValue) { DoublyLinkedList<int> dll = new DoublyLinkedList<int>(values); dll.AddFirst(toAddValue); PexAssert.AreEqual(toAddValue, dll.Head.Value); }