Question
1b) Cyclomatic Complexity (12 points) Note: A detailed discussion of the Cyclomatic Complexity metric can be found in Moodle. Task: 1. Specify the implemented function
1b) Cyclomatic Complexity (12 points) Note: A detailed discussion of the Cyclomatic Complexity metric can be found in Moodle. Task: 1. Specify the implemented function of the statistics method from Listing 1 precisely, but briefly and as generally understandably as possible. Distinguish between normal behavior (successful case) and exceptional behavior. 2. Complete the control flow graph (CFG) on the next page for the statistics method according to Listing 1 or create a new CFG. The initial node is the one with the method signature as content. Note that the Cyclomatic Complexity calculation requires a CFG with exactly one output node (without an outgoing edge). You can easily transform a multi-exit CFG into one by adding an explicit Exit node and connecting all previous exit nodes to the new Exit node with an edge. Hints: Consecutive statements (except the initial node) between which no branching control flow takes place must be combined in a node (basic blocks). Edges at branching nodes must be marked with the corresponding condition. For the CFG, note the Scala semantics regarding exceptions. To make drawing the CFG easier, only consider exceptions that can actually occur at the respective points in the program (i.e. that you could get when calling the method with appropriate arguments). Statements that no longer branch due to this simplification can be viewed as normal non-branching statements. 3. Calculate the Cyclomatic Complexity of the method. If necessary, supplement the CFG from part 1b.2 with additional required elements. Give the complete calculation method!
1b) Cyclomatic Complexity (12 Punkte) Hinweis: Eine ausfhrliche Abhandlung zur Metrik Cyclomatic Complexity finden Sie im Moodle c. Aufgabe: 1. Geben Sie przise, aber knapp und mglichst allgemeinverstndlich, die implementierte Funktion der Methode statistics aus Listing 1 an. Unterscheiden Sie dabei zwischen dem normalen Verhalten (Erfolgsfall) und dem Ausnahmeverhalten. 2. Vervollstndigen Sie den Kontrollflussgraphen (CFG) auf der nchsten Seite fr die Methode statistics gem Listing 1 bzw. erstellen sie einen neuen CFG. Der initiale Knoten ist derjenige mit der Methodensignatur als Inhalt. Beachten Sie, dass die Berechnung der Cyclomatic Complexity ein CFG mit genau einem Ausgangsknoten (ohne ausgehende Kante) bentigt wird. Sie knnen einen CFG mit mehreren Ausgangsknoten leicht in einen solchen umformen, indem Sie einen expliziten Ausgangsknoten Exit" hinzufgen und alle vorherigen Ausgangsknoten ber je eine Kante mit dem neuen Ausgangsknoten Exit verbinden. Hinweise: - Aufeinanderfolgende Statements (auer dem initialen Knoten) zwischen denen kein verzweigender Kontrollfluss stattfindet, mssen in einem Knoten zusammengefasst werden (Basic Blocks). - Kanten an verzweigenden Knoten mssen mit der entsprechenden Bedingung gekennzeichnet sein. - Beachten Sie fr den CFG die Scala-Semantik bzgl. Exceptions. Um das Zeichnen des CFG zu erleichtern, bercksichtigen Sie nur solche Exceptions, die an den jeweiligen Stellen in dem Program auch tatschlich auftreten knnen (d.h., die Sie beim Aufruf der Methode mit entsprechenden Argumenten erhalten knnten). Statements, die aufgrund dieser Vereinfachung nicht mehr Verzweigen, knnen wie normale nicht verzweigende Statements aufgefasst werden. 3. Berechnen Sie die Cyclomatic Complexity der Methode. Ergnzen Sie dazu ggf. den CFG aus Aufgabenteil 1b. 2 um weitere bentigte Elemente. Geben Sie den vollstndigen Rechenweg an! Listing 1: metric.CyclomaticComplexity case class Game(visitorTeam: String, homeTeam: String, visitorScore: Int, homeScore: Int) object CyclomaticComplexity: def statistics(games: List[Game]): String = var wins: Map[String, Int] = Map ( ) var i: Int =0 while ( i = games (i) if (game.homeScore > game.visitorScore) \{ val homeName = game homeTeam wins +=( homeName (wins.getorElse(homeName, 0)+1) ) \} else if (game.visitorScore > game.homeScore) \{ val visitorName = game.visitorTeam wins += (visitorName (wins.getOrElse (visitorName, 0)+1) ) \} i=i+1 \} val winsList: List[(String, Int)] = wins.toList var j: Int =0 var winningTeam: String = " " var winningScore: Int =0 while ( j = winsList (j) if (winningTeam.isBlank || score > winningScore) \{ winningTeam = team winningScore = score \} j=j+1 \} s"SwinningTeam: \$winningScoreStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started