Click Submit to View Solution
The Absolute Beginners Inc. seems to have been fascinated by your work. Recently they have entrusted you with a task of writing a web-based mathematical software (using JavaScript). As part of this software, your team mate has written a small module, which computes area of simple geometric shapes. A portion of the module is shown below.
function square(side) { return side * side }
function rectangle(side1, side2) { return side1 * side2; }
function circle(radius) { return Math.PI * radius * radius; }
function right_triangle(base, height) { return 1 / 2 * base * height; }
Your task essentially is to verify whether each of the above function is returning correct values for given
inputs. For example, a rectangle with length 10 unit and breadth 5 unit will have an area of 50 sq. unit.
This can be verified from the output of the function call
rectangle(10, 5);
However, testing also attempts to point out possible bugs in the software. How would the above code behave
for a call
rectangle(10, -5);
Limitations: This workspace attempts to provide a very simple version of a testing framework. Real life testing frameworks are much more extensive and provide a lot of options like creating test cases from user requirements, automatic reporting of bug when a test case fails, and so on. Nevertheless, this workspace is expected to make a student familiar to testing and some of it's templates and reports.
The code shown above in the textarea is the code against which we have to create our test cases. The displayed code is a modified version, which returns -1 whenever any dimension of a shape is specified as negative. Once this code is ready, we can create a test suite and add test cases as shown below.
Test Suite id | Summary | Script | Expected Output | Actual Output | Manual Testing | Status |
---|---|---|---|---|---|---|
TS0 |
|
No Run | ||||
TS1 |
|
No Run | ||||
TS2 |
|
No Run | ||||
TS3 |
|
No Run | ||||
TS4 |
|
No Run | ||||
TS5 |
|
No Run |
The result of execution of this test suite is displayed below:
Test Suite id | Summary | Script | Expected Output | Actual Output | Manual Testing | Status |
---|---|---|---|---|---|---|
TS0 |
|
Pass | ||||
TS1 |
|
Pass | ||||
TS2 |
|
Fail | ||||
TS3 |
|
Pass | ||||
TS4 |
|
Pass | ||||
TS5 |
|
Pass |
# of test cases passed | |
# of test cases failed | |
Total # of test cases | |
Test suite status |
Note that the call to "circle( -14 )" returns -1 as expected. However, one of the test cases,
"rectangle( 5.5, 10 )" fails. We can verify from the "Actual Output" column that this function didn't return
the correct value. This is a bug.
To identify the source of this bug, we look at the "rectnagle( side1, side2 )" function in our code base.
After observing minutely we find that the code in line #8 should have returned "side1 * side2" instead of
"side1 * side1". We fix this bug, and run the test suite again. We get the following output where the entire
test suite passes.
Test Suite id | Summary | Script | Expected Output | Actual Output | Manual Testing | Status |
---|---|---|---|---|---|---|
TS0 |
|
Pass | ||||
TS1 |
|
Pass | ||||
TS2 |
|
Pass | ||||
TS3 |
|
Pass | ||||
TS4 |
|
Pass | ||||
TS5 |
|
Pass |
# of test cases passed | |
# of test cases failed | |
Total # of test cases | |
Test suite status |