Sure, here are the answers to the questions:
- CFG Diagram:
The CFG diagram for the given code segment is:
[image: CFG Diagram] open
The diagram shows three nodes:
- Node 1: The entry point of the function, which contains the first statement of the code.
- Node 2: The conditional statement, which has three branches:
- Branch 1: The first branch, which executes the statement "print('Positive')" and then jumps to node 3.
- Branch 2: The second branch, which executes the statement "print('Zero')" and then jumps to node 3.
- Branch 3: The third branch, which executes the statement "print('Negative')" and then jumps to node 3.
- Node 3: The exit point of the function, which contains the statement "return".
- Cyclometric Complexity:
The cyclometric complexity of the given code segment is 3.
- Basic Path Sets:
The basic path sets for the given code segment are:
- Path 1: {1, 2, 3}
- Path 2: {1, 2, 4}
- Path 3: {1, 3}
- Test Cases:
Here are some test cases for each of the paths:
- Path 1:
- x = 5, n = 2 (should print "Positive")
- x = 0, n = 2 (should print "Zero")
- x = -1, n = 2 (should print "Negative")
- Path 2:
- x = 5, n = 3 (should print "Positive")
- x = 0, n = 3 (should print "Zero")
- x = -1, n = 3 (should print "Negative")
- Path 3:
- x = 5, n = 1 (should print "Negative Complement")
- x = 0, n = 1 (should print "Negative Complement")
- x = -1, n = 1 (should print "Negative Complement")
Note that these are just some examples of test cases, and more test cases may be needed to fully test the function.