This article discusses testing code that utilizes the Deque data structure. Learn how to effectively create unit tests and ensure your Deque implementation works as expected.
Deque, Java, Testing, Unit Testing, Code Quality
import java.util.ArrayDeque;
import java.util.Deque;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class DequeTest {
@Test
public void testDequeOperations() {
Deque deque = new ArrayDeque<>();
// Adding elements
deque.addFirst(1);
deque.addLast(2);
deque.addFirst(0);
// Assert size is correct
Assertions.assertEquals(3, deque.size());
// Check the order of elements
Assertions.assertEquals(0, deque.peekFirst());
Assertions.assertEquals(2, deque.peekLast());
// Remove elements
Assertions.assertEquals(0, deque.removeFirst());
Assertions.assertEquals(2, deque.removeLast());
// Final size
Assertions.assertEquals(1, deque.size());
}
}
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?