private static void Validate <T>(bool expected, Node <T> head) where T : IEquatable <T> { var result = Question_2_6.IsPalindrome(head); Assert.AreEqual(expected, result); result = Question_2_6.IsPalindromeRecursive(head); Assert.AreEqual(expected, result); }
public void IsPalindromeTest_ReturnTrue() { var testList = new LinkedList(new int[] { 0, 1, 2, 3, 2, 1, 0 }); bool result = Question_2_6.IsPalindrome(testList); Assert.IsTrue(result, $"List {testList} is not palindrome."); testList = new LinkedList(new int[] { 0, 1, 2, 3, 3, 2, 1, 0 }); result = Question_2_6.IsPalindrome(testList); Assert.IsTrue(result, $"List {testList} is not palindrome."); }
public void IsPalindromeTest_ReturnFalse() { var testList = new LinkedList(new int[] { 1, 2, 3, 2, 5 }); bool result = Question_2_6.IsPalindrome(testList); Assert.IsFalse(result, $"List {testList} is palindrome."); testList = new LinkedList(new int[] { 1, 2, 3, 3, 2, 6 }); result = Question_2_6.IsPalindrome(testList); Assert.IsFalse(result, $"List {testList} is palindrome."); }
public void Question_2_6_InvalidCases() { Node <int> nullHead = null; TestHelpers.AssertExceptionThrown(() => Question_2_6.IsPalindrome(nullHead), typeof(ArgumentNullException)); }