Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Introduction

This weeks lab will focus on debugging and testing. In particular, it focuses on introducing new bugs, and insufficient testing. It is based on the sorting function in this weeks homework assignment. The lab will be easier if you have looked at and understood the sorting method already.

What you need to do

Import the project into Eclipse.

You have the same sorting method from the homework, and the same unit tests. As described in the homework, there is a bug related to 0-value chars. We will ignore this bug for now, and instead focus on introducing a new bug!

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. Demonstrate to the TA how you can use the debugger to show where the execution goes wrong, as if you didnt already know what the bug is.

Note: you may ONLY use alphanumeric chars in your tests for this lab. You may use other char values in your homework, however.

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. If you are having trouble coming up with a bug, ask for help!

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

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 if (arr[i] == 0) continue; if (anythingFound == false || arr[i] < arr[smallestIndex]) { smallestIndex = i; anythingFound = true; } } if (anythingFound) { result[count++] = arr[smallestIndex]; arr[smallestIndex] = 0; } } while (anythingFound); return result; } }

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

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 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." ).

pleaaaaaaaaaaase solve.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxxviii Special Issue On Database And Expert Systems Applications Lncs 11250

Authors: Abdelkader Hameurlain ,Roland Wagner ,Sven Hartmann ,Hui Ma

1st Edition

3662583836, 978-3662583838

More Books

Students also viewed these Databases questions

Question

Solve each equation or inequality. | 10 - 4x + 1 5

Answered: 1 week ago

Question

5. Understand how cultural values influence conflict behavior.

Answered: 1 week ago

Question

8. Explain the relationship between communication and context.

Answered: 1 week ago