EECS 2030 E, Fall 2015

What Went Wrong?

 

Task 1A: "Debug's Life"

Download the following Java program: DebugExample

Compile the program and fix the syntactic (i.e., compilation) errors.


Task 1B: It's All Semantics

The DebugExample program simulates user input by calling Math.random(). It is then suppose to increment the input by 5, using a for-loop -- admittedly not the best approach. However, the program contains 2 semantic (i.e., logic) errors. Identify and correct these errors.

One challenge is that the simulated input is unknown to you. Examine the code. How can you learn the value of "user input"? Hint: How do you learn the value of the result?

Once you know the user input, compare the expected output to the output generated. What are the 2 logic errors? Hint: Look at the for-loop.


Task 2: Black-Box Testing - Can You See Me Now?

Black-box testing involves testing a program without knowledge of its code. Instead, you evaluate its correctness by providing carefully chosen input and comparing the actual output to the expected output.

Example
Create a program to calculate the square root of a user-specified number. The program must satisfy the following specifications:

Solutions
The class eecs2030.TestingSquareRoot in the bbt.jar file contains the five (5) possible solutions. The solutions are methods called solution1, solution2, solution3, solution4, and solution5. Each method takes a String argument as input. Only one solution satisfies the all of the specifications.

Which solution is correct? Use the TestDriver here to test solution1. Modify the code to test the other solutions. For each test input, determine the correct output. In Eclipse, remember to add bbt.jar to the classpath: Project menu > Properties > Java Build Path > Libraries > Add External JARs. Navigate to where you saved bbt.jar and select it.

Each test case aims to prove violation of a specification. Which specification does each input evaluate? What is wrong with each solution?

 

 

 

--- End of Exercise ---