Open In App

Slicing – Software Engineering

Last Updated : 22 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.

  1. It can also be used to debug to find the bugs more easily and quickly. 
  2. Slicing techniques were originally defined by Mark Weiser and they were only static at that time.
  3. 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";
}

Output

Hey

There are 2 types of Slicing:

slicing-types
Types of Slicing

Static Slicing

  1. 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.
  2. Static slices are generally larger.
  3. 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;
}

Output

12

Dynamic Slicing  

  1. 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.
  2. Dynamic slices are mostly smaller.
  3. 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;
}

Output

22

Explanation:

  1. 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.
  2. 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.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads

Article Tags :