public void ToStringOnMultipleItemList() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("bar"); list.AddLast("grille"); Assert.AreEqual("{ \"foo\", \"bar\", \"grille\" }", list.ToString()); }
public void ElementAtEndOfList() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("bar"); list.AddLast("grille"); Assert.AreEqual("grille", list.ElementAt(2)); }
public void LastOnLongerList() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("bar"); list.AddLast("grille"); Assert.AreEqual("grille", list.Last()); }
public void WhatIsElement0() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("bar"); list.AddAfter("bar", "grille"); //var expected = new string[] { "foo", "bar", "grille" }; CollectionAssert.Equals("foo", list[0]); }
public void ToArrayOnMultipleItemList() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("bar"); list.AddLast("grille"); string[] expected = new string[] { "foo", "bar", "grille" }; CollectionAssert.AreEqual(expected, list.ToArray()); }
public void Add_First_And_AddLast_Correct() { _list.AddFirst(1); CheckSinglyLinkedListWithSingleState(_list); _list.RemoveFirst(); _list.AddLast(1); CheckSinglyLinkedListWithSingleState(_list); }
public void ElementAtNegativeIndex() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("bar"); list.AddLast("grille"); list.ElementAt(-2); // Assert.AreEqual("bar", }
public void nodeNameDoesNotExist() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("bar"); bool expected = false; Assert.AreEqual(expected, list.NodeNameExists("fool")); }
public void CountNItemList() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("bar"); list.AddLast("grille"); list.AddLast("baz"); Assert.AreEqual(4, list.Count()); }
public void ElementAt3() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("bar"); list.AddLast("grille"); list.AddLast("dog"); list.AddLast("shark"); Assert.AreEqual("dog", list.ElementAt(3)); }
public void AddFirst_and_AddLast_OneItem_CorrectState() { _list.AddFirst(1); CheckStateWithSingleNode(_list); _list.RemoveFirst(); _list.AddLast(1); CheckStateWithSingleNode(_list); }
public void AddAfterLastItem() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("bar"); list.AddAfter("bar", "grille"); var expected = new string[] { "foo", "bar", "grille" }; CollectionAssert.AreEqual(expected, list.ToArray()); }
public void AddFirstOnLongerList() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("bar"); list.AddFirst("grille"); var expected = new string[] { "grille", "foo", "bar" }; CollectionAssert.AreEqual(expected, list.ToArray()); }
public void TestAddAfterNoNext() { var expected = new int[3] { 0, 1, 2 }; var list = new SinglyLinkedList<int>(); list.AddLast(0); var node = list.AddLast(1); list.AddAfter(node, 2); Verify(expected, list); }
public void TestAddBefore() { var expected = new int[3] { 0, 1, 2 }; var list = new SinglyLinkedList<int>(); list.AddLast(0); var node = list.AddLast(2); list.AddBefore(node, 1); Verify(expected, list); }
public void ToArrayOnMultipleItemList() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("bar"); list.AddLast("grille"); string[] expected = new string[] { "foo", "bar", "grille" }; //Console.WriteLine("actual: " + list.ToArray()[1]); //Console.WriteLine("expected: " + expected[0]); CollectionAssert.AreEqual(expected, list.ToArray()); }
public void TestAddAfterLast() { var expected = new int[3] { 0, 1, 2 }; var list = new SinglyLinkedList<int>(); list.AddLast(0); list.AddLast(1); var node = list.AddAfter(list.Last, 2); Verify(expected, list); Assert.AreSame(list.Last, node); }
public void CanFindItemsInLinkedList() { SinglyLinkedList <int> singlyLinkedList = new SinglyLinkedList <int>(5); singlyLinkedList.AddLast(7); singlyLinkedList.AddLast(77); singlyLinkedList.AddLast(23); SinglyLinkedListNode <int> foundNode = singlyLinkedList.Find(77); Assert.IsNotNull(foundNode); Assert.AreEqual(77, foundNode.Value); }
public void CanRemoveFirstItemInLinkedList() { SinglyLinkedList <int> singlyLinkedList = new SinglyLinkedList <int>(5); singlyLinkedList.AddLast(7); singlyLinkedList.AddLast(8); singlyLinkedList.AddLast(9); Assert.AreEqual(5, singlyLinkedList.First.Value); singlyLinkedList.RemoveFirst(); Assert.AreEqual(7, singlyLinkedList.First.Value); }
public void AddAfter() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("grille"); // NOTE: This assert isn't necessary. It is merely here to remind you of / verify the state of the list prior to inserting the new node. var expected = new string[] { "foo", "grille" }; CollectionAssert.AreEqual(expected, list.ToArray()); list.AddAfter("foo", "bar"); expected = new string[] { "foo", "bar", "grille" }; CollectionAssert.AreEqual(expected, list.ToArray()); }
public void CanAddAfterSpecificElement() { SinglyLinkedList <int> singlyLinkedList = new SinglyLinkedList <int>(5); singlyLinkedList.AddLast(7); singlyLinkedList.AddLast(13); Assert.AreEqual(5, singlyLinkedList.First.Value); singlyLinkedList.AddAfter(7, 100); string expectedOutput = "5 7 100 13"; string output = singlyLinkedList.ToString().Trim(); Assert.AreEqual(expectedOutput, output); }
static void Main(string[] args) { SinglyLinkedList <int> list = new SinglyLinkedList <int>(); list.AddLast(1); list.AddLast(2); list.AddLast(5); list.AddLast(1); Console.WriteLine("Input:"); list.PrintList(); Console.WriteLine("\n" + IsPalindrome(list.Nodes[0])); }
public void CaitlinsArrayCount() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("bar"); list.AddLast("grille"); string[] lexpected = new string[] { "foo", "bar", "grille" }; int expected = lexpected.Length; string[] lactual = list.ToArray(); int actual = lactual.Length; Assert.AreEqual(expected, actual); }
public void AddLast_WhenCalled_ShouldAddNodeWithGivenValueToTailOfLinkedList(int range, int value) { // Arrange for (var i = 0; i < range; i++) { _list.Add(i); } var prevSize = _list.Size; var prev = _list.Size == 0 ? null : _list.Get(_list.Size - 1); // Act _list.AddLast(value); // Assert var result = _list.Get(_list.Size - 1); Assert.That( result, Is.Not.Null .And.Property(nameof(SinglyLinkedList <int> .Node.Value)).EqualTo(value)); Assert.That(prev?.Next, Is.EqualTo(_list.Size == 1 ? null : result)); Assert.That(result.Next, Is.Null); Assert.That(_list.Size, Is.EqualTo(prevSize + 1)); if (prevSize == 0) { Assert.That(_list.Head, Is.EqualTo(result)); } }
public void AddLastNodeValueSuccessCases(int[] testCase) { SinglyLinkedList <int> list = new SinglyLinkedList <int>(); foreach (int value in testCase) { list.AddLast(new Node <int>(value)); } Assert.AreEqual(testCase.Length, list.Count, "There was an unexpected number of list items"); Assert.AreEqual(testCase.First(), list.Head.Value, "The first item value was incorrect"); Assert.AreEqual(testCase.Last(), list.Tail.Value, "The last item value was incorrect"); int current = 0; foreach (int value in list) { Assert.AreEqual(testCase[current], value, "The list value at index {0} was incorrect.", current); current++; } }
public void getReceivedData() { while (isRun) { try { string s = ""; int len = 0; // 組合字串. receivedData += sp.ReadLine(); // 分解字串. len = receivedData.Length; for (int i = 0; i < len; i++) { // 組合指令. if (receivedData[i] != '~') { s += receivedData[i]; } else { // 加入指令. commandLinkedList.AddLast(s); s = ""; } } receivedData = s; } catch (System.InvalidOperationException e) { } catch (System.TimeoutException e) { } } }
public void LastOnShortList() { SinglyLinkedList <string> list = new SinglyLinkedList <string>(); list.AddLast("foo"); Assert.AreEqual("foo", list.Last()); }
public void AddLastForAllElementsAndCheckForOrder() { var list = new SinglyLinkedList <int>(); int itemCount = 1000; for (int i = 0; i < itemCount; i++) { list.AddLast(i); } int previous = -1; int numberOfElementsInList = 0; foreach (var item in list) { if (previous > item) { Assert.Fail(); } previous = item; numberOfElementsInList++; } Assert.IsTrue(list.Count == itemCount && numberOfElementsInList == list.Count); }
public void RemoveLastForHalfTheItems() { var list = new SinglyLinkedList <int>(); int itemCount = 1000; for (int i = 0; i < itemCount; i++) { list.AddLast(i); } for (int i = 0; i < itemCount / 2; i++) { list.RemoveLast(); } int current = 0; int numberOfElementsInList = 0; foreach (var item in list) { if (current++ != item) { Assert.Fail(); } numberOfElementsInList++; } Assert.IsTrue(list.Count == itemCount / 2 && numberOfElementsInList == list.Count); }
public static void AddAll <T>(this SinglyLinkedList <T> linkedList, params T[] values) { foreach (T value in values) { linkedList.AddLast(value); } }
public void ToStringOnSingleItemList() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); Assert.AreEqual("{ \"foo\" }", list.ToString()); }
public void CountOneItemList() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); Assert.AreEqual(1, list.Count()); }
public void FirstOnShortList() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); Assert.AreEqual("foo", list.First()); }
public void BeginTestMethod() { target = new SinglyLinkedList<int>(); Assert.AreEqual(target.Leng, 0); target.Add(2); target.Add(3, 1); target.AddLast(5); }
static void Main() { SinglyLinkedList<int> list = new SinglyLinkedList<int>(); list.AddLast(1); list.AddLast(2); list.AddLast(3); list.AddLast(4); list.AddLast(5); list.AddLast(6); list.AddLast(3); Console.WriteLine("FirstIndexOf(6): {0}", list.FirstIndexOf(6)); Console.WriteLine("FirstIndexOf(1): {0}", list.FirstIndexOf(1)); Console.WriteLine("FirstIndexOf(16): {0}", list.FirstIndexOf(16)); Console.WriteLine("LastIndexOf(3): {0}", list.LastIndexOf(3)); Console.WriteLine("LastIndexOf(30): {0}", list.LastIndexOf(30)); Console.WriteLine(list.Count); list.Remove(0); foreach (var item in list) { Console.WriteLine(item); } }
public void AddLast_Should_change_tail_and_set_next_of_previous_tail() { ISinglyLinkedList<int> list = new SinglyLinkedList<int>(new[] { 1 }); var previous = list.Tail; list = list.AddLast(2); Assert.That(list.Tail.Data, Is.EqualTo(2)); Assert.That(previous.Next, Is.EqualTo(list.Tail)); }
public void Adding_Should_increment_length() { ISinglyLinkedList<int> list = new SinglyLinkedList<int>(new[] { 1 }); Assert.That(list.Length, Is.EqualTo(1)); list = list.AddAfter(2,list.Tail); Assert.That(list.Length, Is.EqualTo(2)); list = list.AddFirst(3); Assert.That(list.Length, Is.EqualTo(3)); list = list.AddLast(4); Assert.That(list.Length, Is.EqualTo(4)); }
public void RemoveFirstTest() { SinglyLinkedList<int> sll = new SinglyLinkedList<int>(); sll.AddFirst(40); sll.AddFirst(30); sll.AddFirst(20); sll.AddFirst(10); sll.AddLast(50); sll.RemoveFirst(); sll.RemoveFirst(); Assert.AreEqual(30, sll.Head.Value); Assert.AreEqual(50, sll.Tail.Value); Assert.AreEqual(3, sll.Count); }
public void TestAddLast() { var expected = new int[2] { 0, 1 }; var list = new SinglyLinkedList<int>(); list.AddLast(0); list.AddLast(1); Verify(expected, list); }
public void TestEnumerator() { var expected = new int[4] { 0, 1, 2, 3 }; var list = new SinglyLinkedList<int>(); list.AddLast(0); list.AddLast(1); list.AddLast(2); list.AddLast(3); Verify(expected, list); }
public void TestRemoveLast() { var expected = new int[2] { 0, 1 }; var list = new SinglyLinkedList<int>(expected); list.AddLast(-1); Assert.AreEqual(-1, list.Last.Value); list.RemoveLast(); Verify(expected, list); }
public void TestRemoveValue() { var list = new SinglyLinkedList<string>(); list.AddLast("Expected"); list.AddLast("Expected"); list.AddLast("Not expected"); list.AddLast("Expected"); Assert.IsTrue(list.Remove("Not expected")); Assert.IsFalse(list.Contains("Not expected")); }
public void TestRemoveNode() { var list = new SinglyLinkedList<string>(); list.AddLast("Expected"); list.AddLast("Expected"); var notExpected = list.AddLast("Not expected"); list.AddLast("Expected"); list.Remove(notExpected); bool found = false; var current = list.First; while (current != null && !found) { found = current == notExpected; current = current.Next; } Assert.IsFalse(found); }