public void CreateFromZeroLengthArrayShouldReturnNull() { int[] array = new int[0]; SingleLinkedNode <int> actual = SingleLinkedNode <int> .CreateFromArray(array); Assert.IsNull(actual, "actual should be null since length of array is 0"); }
public void CreateFromArrayShouldResultInHeaderLengthEqualToArrayLength() { int[] array = new int[] { 5, 12, 15, -61, 0 }; SingleLinkedNode <int> actual = SingleLinkedNode <int> .CreateFromArray(array); Assert.AreEqual(array.Length, DoubleLinkedNode <int> .Length(actual), "Length"); }
public void SearchShouldReturnNullWhenNotFound() { int[] array = new int[] { 12, 15, -61, 0, 5 }; SingleLinkedNode <int> actual = SingleLinkedNode <int> .CreateFromArray(array); Assert.IsNull(actual.Search(38129), "Should return null"); }
public void LastShouldReturnFinalNode() { int[] array = new int[] { 12, 15, -61, 0, 5 }; SingleLinkedNode <int> actual = SingleLinkedNode <int> .CreateFromArray(array); SingleLinkedNode <int> last = actual.Last(); Assert.IsNotNull(last, "Last should not be null"); Assert.IsTrue(last.IsLast, "IsLast should be true for last node"); Assert.AreEqual(5, last.Value, "Value should be equal to final array value"); }
public void ToStringShouldPrintValuesInOrder() { int[] array = new int[] { 5, 12, 15, -61, 0 }; SingleLinkedNode <int> actual = SingleLinkedNode <int> .CreateFromArray(array); string toString = actual.ToString(); Assert.IsNotNull(toString, "Should not be null string"); Assert.IsNotEmpty(toString, "Should not be empty string"); Assert.AreEqual("5, 12, 15, -61, 0", toString, "String is incorrect"); }
public void SearchShouldReturnNodeWhenValueFound() { int[] array = new int[] { 12, 15, -61, 0, 5 }; SingleLinkedNode <int> actual = SingleLinkedNode <int> .CreateFromArray(array); SingleLinkedNode <int> result = actual.Search(15); Assert.IsNotNull(result, "Should not return null"); Assert.AreEqual(15, result.Value, "Value"); Assert.AreEqual(-61, result.Next.Value, "Next value"); }
public void CreateFromNullArrayShouldThrowException() { int[] array = null; _ = Assert.Throws(typeof(ArgumentNullException), () => SingleLinkedNode <int> .CreateFromArray(array), "Expected to throw System.ArgumentNullException"); }