0% found this document useful (0 votes)
256 views13 pages

Week 3 Homework

The document discusses test case generation for a triangle classification program. It defines the input domain as the three side lengths of a triangle. Various equivalence classes are identified for scalene, right-angled, isosceles, equilateral, and invalid triangles. A decision table is developed with conditions for side lengths and equality of sides to systematically generate test cases that cover different outcomes of the program. Sample test cases and C++ code are also provided to classify different types of triangles based on the side lengths.

Uploaded by

Candace Lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
256 views13 pages

Week 3 Homework

The document discusses test case generation for a triangle classification program. It defines the input domain as the three side lengths of a triangle. Various equivalence classes are identified for scalene, right-angled, isosceles, equilateral, and invalid triangles. A decision table is developed with conditions for side lengths and equality of sides to systematically generate test cases that cover different outcomes of the program. Sample test cases and C++ code are also provided to classify different types of triangles based on the side lengths.

Uploaded by

Candace Lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Anonymous

SWENG 581
Week 3
11/07/2019

Chapter 6

Exercises
5

Consider
the three domains D1, D2, and D3 shown in Figure 6.16. Domain D3 consists of all those
points lying on the indicated straight line. Assuming that the maximum X and Y span of
all the three domains are [−5, 5] and [−5, 5], respectively, give
concrete values of test points for domain D3.

The concrete values for test points of D3 are (-5,-5), (-4,-4), (-3,-3), (-2,-2), (-1,-1), (0,0), (1,1),
(2,2), (3,3), (4,4), (5,5). The X and Y coordinates are the same because it is straight line passing
through the origin. How did I get those values? Domain D3 is represented by an equation X = Y.

Chapter 9

Exercises 5

Consider the following triangle classification system, originally used by Myers [16]: The
system reads in three positive values from the standard input. The three values A,B, and C
are interpreted as representing the lengths of the sides of a triangle. The system then prints
a message on the standard output saying whether the triangle is scalene, isosceles,
equilateral, or right angled if a triangle can be formed. Answer the following questions for
the above program:
(A) What is the input domain of the system?

Input domain of the system is the inputs passed to the program. i.e Three side lengths of the
Triangle under test.

Example : TriangleClassification (7, 9, 9);

(B) What are the input conditions?

Input conditions are valid inputs and invalid inputs. For length of triangle side input, we require a
positive side length. A valid input to the program returns a valid program output. An invalid input
is an input the program responds with an error.

Example: Valid Input:

new TriangleClassification (7, 9, 9);

Invalid input:

new TriangleClassification (-7, -9, -9);

(C) Identify the equivalence classes for the system?

Equivalence classes are test case execution minimization techniques. An equivalence class is a
set of inputs that the program treats as identical.

Equivalence classes for the system can be identified as below:

EqClass_Scalene - to test the Scalene triangle type

EqClass_RightAngled - to test the Right Angled triangle type

EqClass_Isosceles - to test the Isosceles Triangle

EqClass_Equilateral - to test the Equilateral Triangle

EqClass_NotTriangled

EqClass_Invalid1 to test Invalid side length

EqClass_Invalid2

EqClass_Invalid3;
(D) Identify test cases to cover the identified ECs?

TestInputs Outputs

TriangleClassification(3, 5, 7); Scalene Triangle

TriangleClassification(3, 4,5 ); Right Angled Triangle

TriangleClassification(3, 3, 3); Equilateral Triangle

TriangleClassification(3, 4, 4); Isosceles Triangle

TriangleClassification(2, 3, 9); Check Input.Do not form a triangle

TriangleClassification(-3, 4, 4); ERROR : negative sides

TriangleClassification(3, -4, 4); ERROR : negative sides

TriangleClassification(3, 4, -4); ERROR : negative sides

Sample Program:

/*

* TriangleClassification Program
*
*/

public class TriangleClassification {


private int a;
private int b;
private int c;

// Constructor
public TriangleClassification(int a, int b, int c)
{
this.a = a;
this.b = b;
this.c = c;
}

public String triangleFormed()


{
String outputMessage="";
if (a <= 0 || b <= 0 || c <= 0) {
System.out.println("ERROR : negative sides \n");
}
// Check for side length
if ((a + b <= c) || (a + c <= b) || (b + c <= a)) {
System.out.println("Check Input.Do not form a triangle\n");
}

if ((a == b) && (b == c))


{
outputMessage = "Equilateral Triangle";
}
else if (( a == b) || (b == c) || (a == c))
{
outputMessage = "Isosceles Triangle";
}
else if (( a*a + b*b == c*c) || (b*b + a*a == c*c) || (c*c + a*a ==b*b ))
{
outputMessage = "Right Angled Triangle";
}
else
{
outputMessage = "Scalene Triangle";
}

return outputMessage;
}

public static void main(String[] args)


{
TriangleClassification triangle = new TriangleClassification (7, 9, 9);
System.out.println("Program Output:"+ triangle.triangleFormed());
}
}

Exercises 7

Consider the triangle classification specification. The system reads in three positive values
from the standard input. The three values A,B, and C are interpreted as representing the
lengths of the sides of a triangle. The system then prints a message to the standard output
saying whether the triangle, if it can be formed, is scalene, isosceles, equilateral, or not a
triangle. Develop a decision table to generate test cases for this specification.

The decision table is a tool for requirements management and testing. It is used to model complicated
logic. Decision table testing technique that tests a system behavior for many input combinations. This is a
systematic process of capturing the different input combinations with their system behavior as an output,
in a tabular form. Decision table is a testing technique which used to test the system outcomes possibly
for every input provided to the program. Then, these outcomes are stored in the form of records in tables
which tells about the behavior of the program. This is the one reason why this table is also called a
Cause-Effect table.

A, B and C are the sides of the triangle

● The condition to form a triangle is constraint by the law that is, the sum of the two smaller sides is
always greater than the third side.

● If all three sides are equal then it is an equilateral triangle, if only two are equal then isosceles
otherwise, it is a scalene.

Possible Cases 1 2 3 4 5 6 7 8 9 10 11

C1-1: a < b+c? F T T T T T T T T T T


C1-2: b < a+c? - F T T T T T T T T T

C1-3: c < a+b? - - F T T T T T T T T

C2: a = b? - - - T T T T F F F F

C3: a = c? - - - T T F F T T F F

C4: b = c? - - - T F T F T F T F

A1: Not Triangle X X X

A2: Scalene X

A3: Isosceles X X X

A4: Equilateral X

A5: Impossible X X X

X = is true, - = the condition doesn't need to be checked

If you ask me, what does the X's correlate to? I see it means "is true". is that only for the first 3 numbers
since there are only max 3 X's?

Due to format restrictions proper table Symbol has been shifted I will consider these not a triangle cases
will be 1,2,3 and SCALENE will be 11 case, EQUILATERAL will be 4 case, ISOSCELES will be 7,9,10
cases and IMPOSSIBLE CASES will be 5,6,8.

However, X means this following case is true. And every case will have different condition satisfaction as
I mentioned above in CASE 1,2,3 triangles will not form, whereas triangle will be formed in 11(scalene),
4 (equilateral), 7,9 and 10 (isosceles) for the rest of the case it is impossible 5,6 and 8.

Step to make the decision table:

1. I did list all stub conditions:

● The four condition stubs for the table would be:


a, b, c form a triangle?

✔ a = b?
✔ a = c?
✔ b = c?
2. I did calculate the number of possible combinations

✔ Number of Rules = 2Number of Condition Stubs So therefore, Number of Rules = 24 = 16


3. I did place all of the combinations into the table and reduce the combinations.
4. I did check the combination of cover.

This step helps to check for errors and inconsistent rule.

5. I did fill actions in the Table.

Simple code in CPP implementation.


// Triangle.cpp : Defines the entry point for the console application.

//

//Include header file

//#include "stdafx.h"

#include<iostream>

//Add namespace

using namespace std;

//Declare the class

class Triangle

//Declare variables

float a, b, c;

public:

//Declare the required member functions

void input();
void TriangleType();

};

//Method to check the type of the triangle

void Triangle::TriangleType()

//Test case to check whether the triangle is equilateral

if (a == b == c)

cout << "\nTriangle is equilateral Triangle.\n";

//Test case to check whether the triangle is isocles

else if ((a == b) || (a == c) || (c == b))

cout << "\nTriangle is isoceles Triangle.\n";

//Test case to check whther the triangle is right angled triangle

else if (((a * a) + (b*b) == c*c) || ((a * a) + (c * c) == b*b)

|| ((c * c) + (b * b) == a * a))

cout << "Triangle is Right Angled Triangle.\n";

//Test case to check whether we are unable to make a triangle

else if (((a + b) < c) || (c + b) < a || (a + c) < b)

cout << "\n These sides are unable to make a triangle. Pls try again.";

//Test case to check the scalene triangle

else

cout << "\nTriangle is Scalene Triangle.\n";

//Method to take input

void Triangle::input()

{
cout << "Enter the sides of the triangle.";

cout<<"Values should be between 1 to 50:\n ";

cout << "\na is : ";

//Test case to take the positive input

try {

cin >> a;

if (a < 0)

throw a;

else if (a > 50){

cout << "\nPlease enter the value within 1-50 : ";

cin >> a;

//catch block to handle the exception

catch (float num)

cout << "\nNegative numbers are not allowed.";

cout<<"\nPls again enter the value : ";

cin >> a;

cout << "\nb is : ";

//Test case to take the positive input

try {

cin >> b;

if (b < 0)
throw b;

else if (b > 50){

cout << "\nPlease enter the value within 1-50 : ";

cin >> b;

//catch block to handle the exception

catch (float num)

cout << "\nNegative numbers are not allowed.";

cout<<"\n Pls again enter the value : ";

cin >> b;

cout << "\nc is : ";

//Test case to take the positive input

try {

cin >> c;

if (c < 0)

throw c;

else if (c > 50){

cout << "\nPlease enter the value within 1-50 : ";

cin >> c;

//catch block to handle the exception


catch (float num)

cout << "\nNegative numbers are not allowed.\nPls again enter the value: ";

cin >> c;

//Define the main function

int main()

//create object of the class

Triangle ob;

char ch;

//start do-while loop

do {

//call the methods

ob.input();

ob.TriangleType();

cout << "Do you want to continue (y/n):";

cin >> ch;

} while (ch != 'n');

//pause the system for a while


system("pause"); return 0; }

Task 3: A bank has several different levels of awards/penalties that it showers on its customers.
Both are based on the amount of dollars in customers’ various accounts. Different types of
accounts are calculated differently, even though the trigger amounts are the same for all
accounts. The simple rules for any given period are as follows:
Balances at or below $1,000 are penalized by low interest. While Balances above $1,000 get full
interest.
Which test cases from the following represent "Boundary Value Analysis" technique?
I. Testing with invalid account
✔ II. Testing with balances of $999, $1000, $1001
III. Testing with balances of $990, $995, $999
IV. Testing with a Zero Balance
Task 4: For a certain program that controls a thermostatic switch, the switch is switched off once
the temperature falls below 18 F and then it is turned on when the temperature is more than 21 F.
Identify the Equivalence values which belong to the same class.

I. 12,16,22

II. 24,27,17

III. 14,15,19

✔ IV. 22,23,24

Task 5: In object-oriented programming languages, an interface a program structure which


cannot be instantiated. That is, it must be extended to a new class before it can be instantiated
and code deployed by the compiler. Which of the following techniques can be used to test an
interface?

I. code inspection

✔ II. decision-Table based testing

III. boundary value testing

IV. equivalence class testing

You might also like