Make LinkedQueue generic (#3909)

This commit is contained in:
Kumaraswamy B G
2023-03-06 00:38:42 +05:30
committed by GitHub
parent dd949e9b5d
commit 3e9dd776e5
2 changed files with 95 additions and 35 deletions

View File

@ -0,0 +1,29 @@
package com.thealgorithms.datastructures.queues;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class LinkedQueueTest {
@Test
public void testQue() {
LinkedQueue<Integer> queue = new LinkedQueue<>();
for (int i = 1; i < 5; i++)
queue.enqueue(i);
assertEquals(queue.peekRear(), 4);
assertEquals(queue.peek(2), 2);
assertEquals(queue.peek(4), 4);
final int[] element = { 1 };
// iterates over all the elements present
// as in the form of nodes
queue.forEach(integer -> {
if (element[0]++ != integer)
throw new AssertionError();
});
}
}