Question: Introduction This weeks lab will focus on debugging and testing. In particular, it focuses on introducing new bugs, and insufficient testing. What you need to

Introduction

This weeks lab will focus on debugging and testing. In particular, it focuses on introducing new bugs, and insufficient testing.

What you need to do

Import the project into Eclipse.

Here is your task:

1. Introduce a new bug into the method. This bug should be one that is rare enough that the existing tests DO NOT catch it. So, after you introduce this bug, the given test method should still pass. This will take some creativity!

2. Write another test method that DOES catch your new bug. This new test should fail, but it should also make sense! If you remove your bug, the new test should pass.

3. Debug your new test.

Note: you may ONLY use alphanumeric chars in your tests for this lab.

Creating the bug

In order for the sorting method to work correctly, it has to take the array of chars passed in, and return an array with the same char values, but in sorted order. Currently, this method does do that for the 4 sample inputs given. After you introduce a bug, the method will sometimes produce the wrong output, but it may still give the correct output other times. A method does not have to fail every time for it to count as buggy! In fact, we are asking that your new bug not cause the given test to fail. Your bug might only cause the program to fail when the array is very large, or when it contains a certain value, or even only for a certain specific sequence of characters. The point is that, whatever case causes the error, the existing tests dont produce that case, and your new test does.

--------------------------------------------------

public class MyClass { /* * This method returns an array that contains the sorted contents of arr * It repeatedly finds the smallest char in arr, copies it to the new array, and then replaces * that char in arr with a 0 to mark that it has been taken already. Therefore it skips over * any 0 values that it sees. * This algorithm has a bug! (Hint: 0 could be a valid value for a char!) */ public static char[] sorter(char[] arr) { char[] result = new char[arr.length]; boolean anythingFound; int count = 0; do { int smallestIndex = -1; anythingFound = false; //Find the smallest remaining char, skipping already removed chars for(int i=0; i

---------------------------------------------------

import junit.framework.TestCase; import static org.junit.Assert.*;

public class TestClass extends TestCase{ public void setUp() { } public void testSorter() { char[] arrayToSort = new char[]{'a', 'b', 'c', 'd'}; char[] expected = new char[]{'a', 'b', 'c', 'd'}; assertArrayEquals(expected, MyClass.sorter(arrayToSort)); arrayToSort = new char[]{}; expected = new char[]{}; assertArrayEquals(expected, MyClass.sorter(arrayToSort)); arrayToSort = new char[]{'w', 'e', 'r', 's', 'b', 'd', 'a'}; expected = new char[]{'a', 'b', 'd', 'e', 'r', 's', 'w'}; assertArrayEquals(expected, MyClass.sorter(arrayToSort)); arrayToSort = new char[]{'3', '2', '2', '0'}; expected = new char[]{'0', '2', '2', '3'}; assertArrayEquals(expected, MyClass.sorter(arrayToSort)); } }

------------------------------------------------

Please solve the the program above by using java language.

(solve the class that called MyClass by using the information in the beginning of this page and then test the code by using TestClass "which is a JUnit test.").

I please you guys to solve the program this is my third time posting it!!!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!