Thursday, December 26, 2024
Google search engine
HomeGuest BlogsSoftware Engineering | Slicing

Software Engineering | Slicing

Slicing or program slicing is a technique used in software testing which 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 for the purpose of debugging in order to find the bugs more easily and quickly. 
Slicing techniques were originally defined by Mark Weiser and they were only static in nature at that time. Afterward, Bogdan Korel and Janusz Laski introduced dynamic slicing, which can work for a particular execution of the program. 
It is of 2 types: static slicing and dynamic slicing, these are explained as following below:
 

1. Static slicing: 
 

  • A static slice of a program contains all statements that may affect 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.

2. Dynamic slicing: 
 

  • A dynamic slice of a program contains all the statements that actually affect the value of a variable at any point for a particular execution of the program.
  • Dynamic slices are generally smaller.
  • Considers only a particular execution of the program.

Let us see an example by the given code snippet:
 

CPP




int z = 10;
int n;
cin >> n;
int sum = 0;
if (n > 10)
    sum = sum + n;
else
    sum = sum - n;
cout << "Hey";


Static slice for the variable sum
 

CPP




int n;
cin >> n;
int sum = 0;
if (n > 10)
    sum = sum + n;
else
    sum = sum - n;


Dynamic slice for the variable sum when n = 22; 
 

CPP




int n;
cin >> n;
int sum = 0;
if (n > 10)
    sum = sum + n;


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 affects the value of the variable sum
Hence, the dynamic slice is always smaller than a static slice.
 

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments