get Write a test for the get] method. Make sure to test the cases where [get receives an invalid argument, e.g. [get (28723) when the Deque] only has 1 item, or a negative index. In these cases get should return null. You should disregard the skeleton code comments for Deque.java] and take spec as your primary point. get must use iteration. Task: After you've written tests and verified that they fail, implement [get]

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write tests and implement 

get
Write a test for the [get method. Make sure to test the cases where [get] receives an invalid argument,
e.g.get(28723) when the Deque only has 1 item, or a negative index. In these cases get should return
null. You should disregard the skeleton code comments for Deque.java and take spec as your primary
point.
get must use iteration.
Task: After you've written tests and verified that they fail, implement [get
getRecursive #
Since we're working with a linked list, it is interesting to write a recursive get method, [getRecursive
Copy and paste your tests for the [get method so that they are the same except they call getRecursive
(While there is a way to avoid having copy and pasted tests, though the syntax is not worth introducing-
passing around functions in love is
in
Transcribed Image Text:get Write a test for the [get method. Make sure to test the cases where [get] receives an invalid argument, e.g.get(28723) when the Deque only has 1 item, or a negative index. In these cases get should return null. You should disregard the skeleton code comments for Deque.java and take spec as your primary point. get must use iteration. Task: After you've written tests and verified that they fail, implement [get getRecursive # Since we're working with a linked list, it is interesting to write a recursive get method, [getRecursive Copy and paste your tests for the [get method so that they are the same except they call getRecursive (While there is a way to avoid having copy and pasted tests, though the syntax is not worth introducing- passing around functions in love is in
Expert Solution
Step 1

Here is a sample test case for the get method using iteration:

public void testGetWithIteration() {
   // Create a new Deque object
   Deque deque = new Deque();
   
   // Add three items to the Deque object
   deque.addFirst(1);
   deque.addLast(2);
   deque.addLast(3);
   
   // Assert that the get method returns the expected values for valid indices
   assertEquals(1, deque.get(0));
   assertEquals(2, deque.get(1));
   assertEquals(3, deque.get(2));
   
   // Test the case where the get method receives an invalid index (larger than the size of the Deque)
   try {
      deque.get(3);
      fail("Should have thrown an exception.");
   } catch (IndexOutOfBoundsException e) {
      // expected
   }
   
   // Test the case where the get method receives a negative index
   try {
      deque.get(-1);
      fail("Should have thrown an exception.");
   } catch (IndexOutOfBoundsException e) {
      // expected
   }
}

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Fibonacci algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education