@@ -7,6 +7,9 @@ use std::fmt;
77/// The `Cyclomatic` metric.
88#[ derive( Debug , Clone ) ]
99pub struct Stats {
10+ /// The self_cyclomatic value is used for mantaining information about
11+ /// a space cyclomatic complexity even after the merge is happened.
12+ /// It has been added to handle thee case in the c_unit_after test, look at line 374 for more info.
1013 self_cyclomatic : f64 ,
1114 cyclomatic : f64 ,
1215 n : usize ,
@@ -56,19 +59,12 @@ impl fmt::Display for Stats {
5659impl Stats {
5760 /// Merges a second `Cyclomatic` metric into the first one
5861 pub fn merge ( & mut self , other : & Stats ) {
62+ //Calculate minimum and maximum values
63+ self . cyclomatic_max = self . cyclomatic_max . max ( other. cyclomatic_max ) ;
64+ self . cyclomatic_min = self . cyclomatic_min . min ( other. cyclomatic_min ) ;
65+
5966 self . cyclomatic += other. cyclomatic ;
6067 self . n += other. n ;
61-
62- //Calculate minimum and maximum values
63- if other. n == 1 {
64- self . cyclomatic_max = self . cyclomatic_max . max ( other. cyclomatic ) ;
65- self . cyclomatic_min = self . cyclomatic_min . min ( other. cyclomatic ) ;
66- } else {
67- self . cyclomatic_max = self . cyclomatic_max . max ( other. cyclomatic_max ) ;
68- self . cyclomatic_min = self . cyclomatic_min . min ( other. cyclomatic_min ) ;
69- self . cyclomatic_max = self . cyclomatic_max . max ( other. self_cyclomatic ) ;
70- self . cyclomatic_min = self . cyclomatic_min . min ( other. self_cyclomatic ) ;
71- }
7268 }
7369
7470 /// Returns the `Cyclomatic` metric value
@@ -375,7 +371,9 @@ mod tests {
375371 ]
376372 ) ;
377373 }
378-
374+ /// Test to handle the case of min and max when merge happen before the final value of one module are setted.
375+ /// In this case the min value should be 3 because the unit space has 2 branches and a complexity of 3
376+ /// while the function sumOfPrimes has a complexity of 4.
379377 #[ test]
380378 fn c_unit_after ( ) {
381379 check_metrics ! (
0 commit comments