Sei sulla pagina 1di 6

Faishal Arhinza (B031610456)

Question 1

Figure 1
This code snippet takes an integer and sums the positive numbers of that integer. For
example, the input in 6. The code above will sum all numbers until the number equal to the
input number, 6. i.e. 1+2+3+4+5+6 = 21. Thus, the output is 21. Other test cases and outputs
are shown below.
Test Input (Enter a positive Output (Sum)
Case integer:)
TC1 1 1
TC2 2 3
TC3 3 6
TC4 4 10
TC5 50 1275
Table 1
1. Create a control flow graph for the code snippet in Figure 1 2.
Identify:
a. Min test case to reach 100% statement coverage
b. Min test case to achieve 100% decision coverage

CODE :

1 int n, sum = 0;
2 cout << "Enter a positive integer: ";
3 cin >> n;
4 for (int i = 1; i <= n; ++i) {
5 sum += i;
}
6 cout << "Sum = " << sum;
7 return 0;

1. Data flow diagram


2. Identify:
a. Min test case to reach 100% statement coverage ( 1 test)
Test case : 1-2-3-4-5-6-7
b. Min test case to achieve 100% decision coverage (2 test)
Test case 1 : 1-2-3-4-5-6-7
Test case 2 : 1-2-3-4-5-4-5-6-7
Question 2

// Check prime number

bool checkPrime(int n)

int i;

bool isPrime = true;

for(i = 2; i <= n/2; ++i)

if(n % i == 0)

isPrime = false;

break;

return isPrime;
}

Figure 2
The code snippet above checks whether the integer n, is a prime number and returns a Boolean.
A prime number (or a prime) is a natural number greater than 1 that cannot be formed by
multiplying two smaller natural numbers. A natural number greater than 1 that is not prime is
called a composite number. For example, 5 is prime because the only ways of writing it as a
product, 1 × 5 or 5 × 1, involve 5 itself.
1. Create a control flow graph for the code snippet in Figure 2.
2. Identify:
a. Min test case to reach 100% statement coverage
b. Min test case to achieve 100% decision coverage
1. Data flow diagram

2. Identify:
a. Min test case to reach 100% statement coverage
Test case : 1A-2B-3C-4D-5G-6H
b. Min test case to achieve 100% decision coverage
Test case 1 : 1A-2B-3C-4D-5F-3C-4D-5G-6H
Test case 2 : 1A-2B-3C-4D-5G-6H
Test case 3 : 1A-2B-3C-4D-5F-3C-4E-6H
Test case 4 : 1A-2B-3C-4E-6H

Question 3
A new customer that signs up for a loyalty card account will be entitled for 20% discount for
all purchases today only. An existing customer with a loyalty card will get a 15% discount on
all purchases. If a customer has a coupon, they will receive a 25% discount but it cannot be
used together with the new customer discount. However, it can be used together with the
existing customers with loyalty card by adding the total discount. Create a decision table for
this scenario. The output of the decision table should be the total amount of discount received.

Conditions R1 R2 R3 R4 R5 R6 R7 R8
New Customer T T T T F F F F
Existing Customer F F F F T T F F
Purchasing Today T F F T T/F T/F T/F F
Using Coupon F F T T T F T F
Actions
20% Discount T F F T F F F F
15% Discount F F F F T T F F
25% Discount F F T F T F T F
25% + 15% Discount F F F F T F F F

Potrebbero piacerti anche