Question
Software Testing Examine the provided LimitedList.java file. Once you understand what the class does and how it works, define the following information using Input Space
Software Testing
Examine the provided LimitedList.java file. Once you understand what the class does and how it works, define the following information using Input Space Partitioning methods (Interface-based and Functionality-based):
a) All input variables (including the state variables)
b) Characteristics of the input variables defined in (a)
c) The blocks you partitioned based on the characteristics defined in (b).
d) Each partitions Base block.
e) Values in each block (Hint: Refer to the characteristics you defined in (b)).
f) A Test Suite that satisfies Basic Choice Coverage.
LimitedList.java
import java.util.stream.IntStream;
public class LimitedList { // Overview: a LimitedList is a First-In, First-Out data structure with a user-defined size limit // A typical List is [], [o1], or [o1, o2], where neither o1 nor o2 // are ever null. Older items are listed before newer ones.
//State Variables private final Object[] items; //Allows LimitedList to be any object type private final int[] item_ids; private int size, older, newest; private final int limit;
public LimitedList (int userLimit) { if (userLimit < 0) { throw new IllegalArgumentException ("LimitedList.constructor"); } this.limit = userLimit; items = new Object[this.limit]; item_ids = new int[this.limit]; size = 0; older = 0; newest = 0; }
public void addToList (Object o, int id) throws NullPointerException, IllegalStateException { // Modifies: LimitedList itself // Effects: If argument is null throw NullPointerException // else if this is full or id already exists, throw IllegalStateException, // else make o the newest item of the LimitedList if (o == null) { throw new NullPointerException ("LimitedList.addToList"); } else if (size == limit) { throw new IllegalStateException ("LimitedList.addToList"); } else if( IntStream.of(item_ids).anyMatch(x -> x == id) ) //Determines if id is a repeat { throw new IllegalStateException ("LimitedList.addToList"); } else { size++; items[newest] = o; item_ids[newest] = id; newest = (newest + 1) % limit; } } public Object removeFromList () throws IllegalStateException { // Modifies: LimitedList itself // Effects: If list is empty, throw IllegalStateException, // else remove and return oldest item in LimitedList if (size == 0) { throw new IllegalStateException ("LimitedList.removeFromList"); } else { size--; Object o = items[ (older % limit) ]; items[older] = null; item_ids[size] = 0; older = (older + 1) % limit; return o; } } //[Client requested functionality] public Object peekAtList (int id) throws IllegalStateException { // Modifies: LimitedList itself // Effects: If list or id is empty, throw IllegalStateException, // else return the requested item based on the ID if (size == 0 || id == 0) { throw new IllegalStateException ("LimitedList.peekAtList"); } else { for(int i = 0; i < limit; i++) { if(item_ids[i] == id) { return items[i]; } } } throw new IllegalStateException ("LimitedList.peekAtList"); } //Hint: These might be useful characteristics public boolean isEmpty() { return (size == 0); } public boolean isFull() { return (size == limit); }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started