Question: Learning outcomes Find bugs using black-box testing. Write tests against a defined interface. Instructions Attached to this assignment you will find project below. The project
Learning outcomes Find bugs using black-box testing. Write tests against a defined interface. Instructions Attached to this assignment you will find project below. The project contains an interface defining a stack of ints (IntStack), three classes implementing of that interface (IntStack0, IntStack1, and IntStack2), and some infrastructure to simplify writing tests for the aforementioned classes. After unzipping, you should be able open the project using the Open button on the main IntelliJ splash screen. (It shouldnt be too difficult to translate this project to another IDE, so youre free to use another if you prefer. If youd like help setting that up, feel free to email me.) The IntStack classes are provided in .class form only, meaning you do not have access to their source code. Two of them contain bugs and one is correct. Your assignment is write tests for the IntStack classes and determine which of the classes are bugged and which is correct. To make that determination, it should be sufficient to write tests that properly exercise all of the properties of the operations of the stack. That is to say, the bugs are not supposed to be tricky or difficult to find. New tests should be added to the IntStackTestBase class so that they can be inherited by the IntStack0Test, IntStack1Test, and IntStack2Test classes, which actually test each of the corresponding IntStack classes. In your tests, you should use the newInstance method rather than use the new operator. This is to ensure that you get an instance of whichever IntStack class youre currently testing. for each bugged class is available if you can accurately describe what the source or cause of the bug is.
public class IntStack0 implements IntStack { int size = 0; int[] values = new int[10]; public IntStack0() { } public void push(int i) { if (this.size < this.values.length) { this.values[this.size] = i; ++this.size; } else { int[] oldValues = this.values; this.values = new int[this.values.length * 2]; if (oldValues.length >= 0) { System.arraycopy(oldValues, 0, this.values, 0, oldValues.length); } this.push(i); } } public int pop() { if (this.size > 0) { int ret = this.values[this.size]; --this.size; return ret; } else { throw new ArrayIndexOutOfBoundsException(); } } public int size() { return this.size; } public boolean isEmpty() { return this.size == 0; } } ----------------------------------------------------------------------
public class IntStack1 implements IntStack { int size = 0; int[] values = new int[10]; public IntStack1() { } public void push(int i) { if (this.size < this.values.length) { this.values[this.size] = i; ++this.size; } else { int[] oldValues = this.values; this.values = new int[this.values.length * 2]; this.push(i); } } public int pop() { if (this.size > 0) { int ret = this.values[this.size]; --this.size; return ret; } else { throw new ArrayIndexOutOfBoundsException(); } } public int size() { return this.size; } public boolean isEmpty() { return this.size == 0; } } --------------------------------------------------------------
public class IntStack2 implements IntStack { int size = 0; int[] values = new int[5]; public IntStack2() { } public void push(int i) { if (this.size < this.values.length) { this.values[this.size] = i; ++this.size; } else { int[] oldValues = this.values; this.values = new int[this.values.length * 2]; if (oldValues.length >= 0) { System.arraycopy(oldValues, 0, this.values, 0, oldValues.length); } this.push(i); } } public int pop() { if (this.size > 0) { --this.size; int ret = this.values[this.size]; return ret; } else { throw new ArrayIndexOutOfBoundsException(); } } public int size() { return this.size; } public boolean isEmpty() { return this.size == 0; } } --------------------------------------------------------
public class IntStack0Test extends IntStackTestBase{ @Override protected IntStack0 newInstance() { return new IntStack0(); } }
------------------------------------------------------
import org.junit.jupiter.api.Test; public abstract class IntStackTestBase{ protected abstract T newInstance(); @Test void testNewInstance() { IntStack stack = newInstance(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
