|
| 1 | +package com.thealgorithms.misc; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 5 | + |
| 6 | +import com.thealgorithms.datastructures.lists.SinglyLinkedList; |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | + |
| 9 | +public class PalindromeSinglyLinkedListTest { |
| 10 | + @Test |
| 11 | + public void testWithEmptyList() { |
| 12 | + assertTrue(PalindromeSinglyLinkedList.isPalindrome(new SinglyLinkedList())); |
| 13 | + } |
| 14 | + |
| 15 | + @Test |
| 16 | + public void testWithSingleElement() { |
| 17 | + var exampleList = new SinglyLinkedList(); |
| 18 | + exampleList.insert(100); |
| 19 | + assertTrue(PalindromeSinglyLinkedList.isPalindrome(exampleList)); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + public void testWithListWithOddLengthPositive() { |
| 24 | + var exampleList = new SinglyLinkedList(); |
| 25 | + exampleList.insert(1); |
| 26 | + exampleList.insert(2); |
| 27 | + exampleList.insert(1); |
| 28 | + assertTrue(PalindromeSinglyLinkedList.isPalindrome(exampleList)); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void testWithListWithEvenLengthPositive() { |
| 33 | + var exampleList = new SinglyLinkedList(); |
| 34 | + exampleList.insert(10); |
| 35 | + exampleList.insert(20); |
| 36 | + exampleList.insert(20); |
| 37 | + exampleList.insert(10); |
| 38 | + assertTrue(PalindromeSinglyLinkedList.isPalindrome(exampleList)); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testWithListWithOddLengthNegative() { |
| 43 | + var exampleList = new SinglyLinkedList(); |
| 44 | + exampleList.insert(1); |
| 45 | + exampleList.insert(2); |
| 46 | + exampleList.insert(2); |
| 47 | + assertFalse(PalindromeSinglyLinkedList.isPalindrome(exampleList)); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testWithListWithEvenLengthNegative() { |
| 52 | + var exampleList = new SinglyLinkedList(); |
| 53 | + exampleList.insert(10); |
| 54 | + exampleList.insert(20); |
| 55 | + exampleList.insert(20); |
| 56 | + exampleList.insert(20); |
| 57 | + assertFalse(PalindromeSinglyLinkedList.isPalindrome(exampleList)); |
| 58 | + } |
| 59 | +} |
0 commit comments