Question on Cyclomatic Complexity | Software Engg.

Hello friends, welcome to Gate Smashers. In today's video, we are going to discuss two questions. Both the questions are on the important topic of software engineering So guys, immediately like the video and subscribe to the channel, if you have not done it yet. And please press the bell button so that you get all the latest notifications. So, let's start with question number one. Which of the following is the white box. testing technique? So first let me tell you that the testing is, one of the most important in software engineering. And here you will get questions in every competitive exam, whether you take the NET exam, IT officer exam, KVS, or any competitive exam, you will definitely get questions on testing related to CSE.

And here if we talk about it, the question has come on white box testing. So in white box testing, we have the tester. The tester is the one who is doing the test. The tester should have knowledge of the internal structure. So internal structure means the source code program, he should know that. And each module. What do we do with every block of the program? We try to test it. And we create the test cases. And what do we do with those test cases? we test the test cases. So here if we take the example of white box testing. So the path coverage. Or we call it the basic path. So we say that it is part of white box testing.

But the equivalence class testing. Cause effect graph. State-based testing, all three come under the black box. And this comes under the white box. And basically, what do we do in the path coverage? In the path coverage, as we know that, if we talk about software or talk about a program. So that program or software has multiple entry points & multiple exit points. And what do we have to do? We have covered up all those points. This means we have to cover up all the blocks in a program And covering up means so many test cases are there. We have checked all those test cases. And here we use the method of cyclomatic complexity. and through that cyclomatic complexity We find the independent parts and try to reduce the number of test cases. Such as if we talk about, let's say in the program, There is IF, ELSE.

After that again there is IF and ELSE. If we take any simple program, so based on this, if we talk about this IF So based on this, we have to create a test case. We will create a test case based on ELSE & will create a test case
based on this IF & this ELSE. All the modules, all the test cases, So you have to check all the test cases. So you have to check all the multiple blocks you have within the program. So here, Path coverage is the part of white boxing. then if we talk about, Equivalence Class testing. So, what do we do in equivalence class testing? We divide test data into groups. This means we don't cover up all test cases, we are not able to cover all test cases.

So what did we do? We form groups. Let's say, if we talk, I will give a simple example. We formed groups that less than 18, Let's say take the example of a movie. Whether that movie, means if the age is less than 18. Then they can't see the movie and if the age is more than 56, then they can't see it.

Then who can see that movie? Whose ages are greater than 18 and less than 56. So what have we done here? We form groups. Now we will take some test cases which will be less than 18. Some test cases will be taken that will come in between them. And take a few test cases which will come under this data. So what will we do? We will check those test cases. So here we reduce the test cases by grouping up. But it comes under the black box testing. Then cause-effect graph. If we talk about the cause-effect graph, then basically it tells the relationship between cause and effect. And through the graph, in such a way, let's say, there is a cause. and that cause is leading to which effect? This means the effect we are having, on what basis that effect is happening, and what is its cause? The relationship between them, we denote it based on the graph.

That's a cause-effect graph. Let's say, here I will give you a simple example. Here, we have a cause C1, let's say it's a user name. And we have another cause C2. Let's say, it is a password. Now here if I put an and between these two. So it means that If you enter both a valid username & password, What will be the effect then? Your login will be done. But if either of the two is wrong, either the username or password is wrong What will be the effect then? Login will be unsuccessful. So this is how we test the application, or our entire software. So that's also a part of Black box. Then state-based testing. Or we also call it state transition, State Transition Testing. So what does state transmission mean? It provides multiple inputs.

That is, multiple input is given in the app, and then based on that we check what the output is coming. And we give inputs like give some positive inputs and give some negative inputs and based on that, we are checking what the output is coming. As I give a simple example, take the example of an ATM. So in the ATM, If I put in a valid PIN. I entered the valid PIN. So my transaction was successful. Let's say, I entered
the PIN incorrectly twice. & then at the third time, I entered the correct PIN. So the transaction has been completed.

Let's say, all three times I
entered the PIN incorrectly. So the transaction has failed. The card has been blocked as well. So that means if you are giving input. Based on the input you are giving, at which state you are reaching? That's called state transmission. Like, let's say If we start the transaction. I entered the PIN the first time which is the first pin. And if I do that successfully, then my transaction will be succeeded and if I entered the wrong PIN, So in a way, the transaction will get declined.

Then I entered it again. If I entered the correct PIN, then the transaction will be successful, otherwise, it got declined. & the third time, if I entered the wrong PIN then obviously the card will get blocked here. So based on every single input, Whether that input is positive input or negative input. We are reaching a certain state, which is called state transmission testing or state-based testing. So all three come under the black box and the path coverage
comes under the white box. In the path coverage, I mentioned cyclomatic complexity, Whatever our software is. That software is checked in multiple blocks, So it will take me a lot of time to check. Because you have to cover up all the test cases.

So instead of covering up so many test cases. We find the independent path. We find the independent modules and that independent modules we find out based on cyclomatic complexity. We make it a Control graph or we call it a flow graph. And based on that flow graph or control graph. We find out cyclomatic complexity. Which tells you that the number of different or you can say the linearly Independent Paths & what can we call those independent paths? This is our test case. So just cover up those test cases, So don't need to do all, which will consume your time. Because the number of test cases will be less Making less doesn't mean, you don't have to ignore it. All the test cases have to be covered up but we reduce it by using cyclomatic complexity So what is cyclomatic complexity that we will discuss in the next question. The next question is. to find the cyclomatic complexity of the following flow graph of the software code.

So here I have a flow
graph in the question. & cyclomatic complexity is to be found out. So the cyclomatic complexity, as I told you in the first question. We find out in the path coverage or basic path testing to minimize the test cases or you can say that to find the number of independent paths, linearly independent paths. So to find out the independent paths or to find out the cyclomatic complexity, We have multiple formulas. Like we have a formula, Number of Regions plus one. Number of bounded regions plus one So you find out the number of bounded regions And add one to it. Second is the number of edges, that we can write. Take out the number of edges from the graph given. Minus the number of vertexes, the number of vertexes will
also be given in our graph. Plus two. This is the formula & the third is to take out the predicate notes. notes where two edges emerge from or you can say the conditional notes are called predicate notes. Plus one So any of these three formulas you can use. So the best is to find out the regions, always follow this, number of regions plus one So, we have to find bounded regions, so bounded means Those who are surrounded by all sides, should not be open.

So see, here if we talk about this region, Look at this region Surrounded by all sides of the edges, so here, it will come my region one (R1) Look at this, it's my second region (R2). it is also bounded by all sides, so it has become the R2 region. The third is, look at this, this is forming, this one is complete, R3 So how many bounded regions are there? Three So if you have to do 3 +1, So How many number of regions are there, If you have done 3+1, then the cyclomatic complexity will be 4 So the answer is 4. But here if we talk about, we should find out, we should see, which 4 independent paths are there. So see, if we start with N1, then from N1 to N2 and N3. From N3 to N5, then N6. If you leave the loop if I write here, N1, N2, N3, N5, N6, N7, N8 And from N8, you go back to N1. One will be this. Second, N1, N2 From N2, you go to N4 From N4 to N5, from N5 to N6, N7, N8, N1.

Now let's do the loop. N1, N2, N3, take the N3 first. Then N5, N6, N7. From N7, you can again go back to N6 because there is a loop, E8 edge. From N6, you to N7, then N8 in this way you do it. And here we have taken N3, now we take N4 instead of N3. So here you replace N4 with N3 & the rest of the Path is totally the same.

So here, how many number of independent paths do I have? Four, which we called Cyclomatic complexity. Thank you..