Exercises related to Robust Development Methodologies - Part 2
Cyclomatic Complexity
Exercice 1
What is the cyclomatic complexity of a switch case?
void a_case (){
char operation = '';
switch (operation) {
case "+":
printf("operation: %c\n");
break;
case "-":
printf("operation: %c\n");
break;
case "=":
printf("operation: %c\n");
break;
default:
printf("operation: none\n");
break;
}
}
Exercice 2
Given the function below, calculate the cyclomatic complexity
void foo1 () {
int array[] = {1, 7, 4, 9, 12, 7, -1, 13};
const int kArraySize = 8;
int min = array[0];
for(int i = 0; i < kArraySize; i++){
if( array[i] < min){
min = array[i];
}
}
printf("Array minimum = %d\n", min);
}
Note
Did you know that
Scitool Understand
will generate a control flow diagram from software? Here a simple
example:

Critical: How to Write git Commit Messages
Exercice 3
Read the article Write Better Commit Messages and the respond to the following questions:
- What is the structure of a commit message?
- What types of commits are there?
- What does one put in the footer section usually? What is its purpose?
- What are the
gitcommit best practices?