0% found this document useful (0 votes)
3 views6 pages

Sheet 7 - Syntax Based Testing

The document outlines a course on Software Verification and Validation, focusing on syntax-based testing and program mutation. It includes exercises on grammar-based mutation, defining test cases, and understanding terminal and production rules. Additionally, it discusses identifying mutants in code and determining test cases for mutant reachability and infection.

Uploaded by

miraabdelaziz038
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)
3 views6 pages

Sheet 7 - Syntax Based Testing

The document outlines a course on Software Verification and Validation, focusing on syntax-based testing and program mutation. It includes exercises on grammar-based mutation, defining test cases, and understanding terminal and production rules. Additionally, it discusses identifying mutants in code and determining test cases for mutant reachability and infection.

Uploaded by

miraabdelaziz038
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/ 6

Arab Academy for Science Technology and Maritime Transport

College of Computing and Information Technology

Course Software Verification and Validation


Course Code SE492
Lecturer Dr. Hagar Hussein
TA Salma ElKady

Sheet 7 (Syntax-Based Testing – Part I)

A. Grammer-Based Mutation

Question 1

a. Define a set of test cases that satisfied TSC but not PDC.
b. Complete number (A) to satisfy PDC.
c. Draw syntax-tree for: xx * 33

Answer
Step 1: Define all terminals & all production rules

➢ Terminals: "a", ..., "z" (26), "0", ..., "9" (10), “+”, “-“, “*”, “/” (4).
➢ Production rules:
o expr ::= id
o expr ::= num
o expr ::= expr op expr
o id ::= letter
o id ::= letter id
o num ::= digit
o num ::= digit num
o op ::= "+"
o op ::= "-"
o op ::= "*"
o op ::= "/"
o letter ::= "a" (and similarly for "b" to "z", 26 rules)
o digit ::= "0" (and similarly for "1" to "9", 10 rules)

1
Step 2: Extract TSC & PDC

(A)
➢ TSC: Ensure every ingredient (terminal) is used at least once
➢ TSC (Pass-by all terminals at least once)
o "a", ..., "z" (26 Tests).
o "0", ..., "9" (10 Tests).
o “+”, “-“, “*”, “/” (4 Tests).
➢ Exclude what have covered

What is left:
➢ id ::= letter id
➢ num ::= digit num

So, the answer is


o "a", ..., "z" (26 Tests).
o "0", ..., "9" (10 Tests).
o “+”, “-“, “*”, “/” (4 Tests).

(It doesn’t satisfy PDC)

(B)
o "a", ..., "z" (26 Tests).
o "0", ..., "9" (10 Tests).
o “+”, “-“, “*”, “/” (4 Tests).
o 23
o Zy

2
(C)

Question 2
expr ::= term | expr "+" term
term ::= factor | term "*" factor
factor ::= num | var | "(" expr ")"
num ::= digit | num digit
digit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
var ::= "x" | "y" | "z"

a. Show difference between TSC and PDC.


b. Perform TSC & PDC.

Answer
Step 1: Define all terminals & all production rules

➢ Terminals: "0", ..., "9" (10), "x","y","z" (3).


➢ Production rules:
o expr ::= term
o expr ::= expr "+" term
o term ::= factor
o term ::= term "*" factor
o factor ::= num
o factor ::= var
o factor ::= "(" expr ")"
o num ::= digit
o num ::= num digit
o digit ::= "0" (and similarly for "1" to "9", 10 rules)
o digit ::= "x" (3 rules)

3
Step 2: Answer the following

(A)

(B)
➢ TSC: Ensure every ingredient (terminal) is used at least once
➢ TSC (Pass-by all terminals at least once)
o "0", ..., "9" (10 Tests).
o “x”, “y“, “z” (3 Tests).

What is left:
➢ term ::= term * factor
➢ expr ::= expr + term

➢ PDC (Pass-by all production rules at least once)


o "0", ..., "9" (10 Tests).
o “x”, “y“, “z” (3 Tests).
o x*y
o 1*2
o x+y
o 1+2

4
B. Program Mutation

Question 1

a. Identify the mutant.


b. Determine a test case to show whether its killed or not.

Answer
a. i = 1 is mutant of i=0

b. x={1,0,0} (Not Killed)


x={0,1,0} (Killed)

Question 2

a. Find a test case that doesn’t reach the mutant.


b. Find test case that satisfies reachability but not infection of mutant.

Answer
a. Mutant is always reached even if x = null.
b. Infection always occurs even if x=null because i always has wrong value after initialization.

5
Question 3

a. Find a test case that doesn’t reach the mutant.


b. Find test case that satisfies reachability but not infection of mutant.

Answer
a. If x = null or array is empty, then the mutant us never reached.
b. Any input with all zeros will reach but not infect as x = [0] or x = [0,0]

Question 4

c. Find a test case that doesn’t reach the mutant.


d. Find test case that satisfies reachability but not infection of mutant.

Answer
c. An empty array skips the for loop entirely.
d. findIndex(new int[] {10, 5, 6}, 5)
a. Original: Starts from index 0 → doesn’t match 10 → matches 5 at index 1 → returns 1.
b. Mutant: Starts from index 1 → matches 5 at index 1 → returns 1.

You might also like