Deque Test Algorithm

The Deque Test Algorithm is a diagnostic tool used to evaluate the performance of a particular Deque (Double-ended queue) implementation. Deques are a generalization of stacks and queues that allow elements to be added or removed from both ends, enabling efficient insertion and deletion operations. The algorithm focuses on testing the efficiency, correctness, and robustness of various operations such as adding, accessing, and removing elements from the Deque, ensuring that the implementation adheres to the expected standards and functional specifications. To perform the Deque Test Algorithm, a series of test cases are designed to cover all possible scenarios and edge cases. Some of these tests may include checking the size of the Deque after inserting or removing elements, verifying if the correct elements are being added or removed from both ends, and ensuring that the Deque implementation can handle large datasets without compromising on performance. Additionally, the algorithm should also validate the implementation's behavior when faced with invalid inputs and boundary conditions, such as attempting to remove an element from an empty Deque or exceeding the maximum capacity. By thoroughly testing the Deque implementation using this algorithm, developers can identify potential issues and inefficiencies, enabling them to optimize the data structure for real-world applications.
package deque

import org.jetbrains.spek.api.Spek
import org.junit.Assert.*

/**
 * Spek BDD Test for Deque Class
 */
class DequeSpecs: Spek(spekBody = {
    given("Given an Empty Queue") {
        val deque: Deque<Int> = Deque()
        on("Peeking first value") {
            val value = deque.getFirst()
            it("should result in null value") {
                assertNull(value)
            }
        }
        on("Peeking last value"){
            val value = deque.getLast()
            it("should result in a null value"){
                assertNull(value)
            }
        }
    }
    given("Given a Queue with 1 value") {
        val deque: Deque<Int> = Deque()
        deque.addFirst(1)
        on("Fetching first value") {
            val value = deque.getFirst()
            it("1. should not result in null value") {
                assertNotNull(value)
                assertEquals(1, value)
            }
            it("2. should have removed the final value"){
                assertNull(deque.peekFirst())
            }
        }
    }
    given("Given a Queue with 1 value") {
        val deque: Deque<Int> = Deque()
        deque.addFirst(1)
        on("Fetching last value") {
            val value = deque.getLast()
            it("1. should not result in null value") {
                assertNotNull(value)
                assertEquals(1, value)
            }
            it("2. should have removed the final value"){
                assertNull(deque.peekFirst())
            }
        }
    }
    given("Given a Queue with 2 values") {
        val deque: Deque<Int> = Deque()
        deque.addFirst(2)
        deque.addFirst(1)
        on("Fetching first value") {
            val value = deque.peekFirst()
            it("should not result in null value") {
                assertNotNull(value)
                assertEquals(1, value)
            }
        }
        on("Fetching last value") {
            val value = deque.peekLast()
            it("should not result in null value") {
                assertNotNull(value)
                assertEquals(2, value)
            }
        }
        on("Removing last value") {
            deque.removeLast()
            it("There should be 1 value left on the queue") {
                val value = deque.peekFirst()
                assertNotNull(value)
                assertEquals(1, value)
            }
        }
    }
})

LANGUAGE:

DARK MODE: