Slicing – Software Engineering
Last Updated :
22 Dec, 2023
This article focuses on discussing Slicing in Software Engineering.
What is Slicing?
Slicing or program slicing is a technique used in software testing that takes a slice or a group of program statements in the program for testing particular test conditions or cases that may affect a value at a particular point of interest.
- It can also be used to debug to find the bugs more easily and quickly.Â
- Slicing techniques were originally defined by Mark Weiser and they were only static at that time.
- Afterward, Bogdan Korel and Janusz Laski introduced dynamic slicing, which can work for a particular execution of the program.Â
Below is the C++ program to implement Slicing:
C++
// C++ program to implement slicing
#include <iostream>
using namespace std;
int main()
{
int n = 12;
int sum = 0;
if (n > 10)
sum = sum + n;
else
sum = sum - n;
cout << "Hey";
}
There are 2 types of Slicing:
Static Slicing
- A static slice of a program contains all statements that may impact the value of a variable at any point for any arbitrary execution of the program.
- Static slices are generally larger.
- It considers every possible execution of the program.
Below is the C++ program to implement static slicing:
C++
// C++ program to implement static
// slicing
#include <iostream>
using namespace std;
// Driver code
int main()
{
int n = 12;
int sum = 0;
if (n > 10)
sum = sum + n;
else
sum = sum - n;
cout << sum;
}
Dynamic Slicing Â
- A dynamic slice of a program contains all the statements that actually impact the value of a variable at any point for a particular execution of the program.
- Dynamic slices are mostly smaller.
- Considers only a particular execution of the program.
Below is the C++ program to implement dynamic slicing for the variable sum when n = 22:
C++
// C++ program to implement dynamic
// slicing
#include <iostream>
using namespace std;
// Driver code
int main()
{
int n = 22;
int sum = 0;
if (n > 10)
sum = sum + n;
cout << sum;
}
Explanation:
- As it can be observed in the above example the static slice takes all the possible execution (in this case it is 2) of the program which may affect the value of the variable sum.
- Whereas in the case of dynamic slicing, it considers only a particular execution (when n = 22) of the program which actually impacts the value of the variable sum.Â
Hence, the dynamic slice is always smaller than a static slice.
Share your thoughts in the comments
Please Login to comment...