Bladeren bron

Comment ratio: only keep a 3-digit precision to improve reproducibility between python2 / python3

Emmanuel Olivi 2 jaren geleden
bovenliggende
commit
d6466b798b

+ 2 - 2
metrixpp/mpp/api.py

@@ -1183,8 +1183,8 @@ class MetricPluginMixin(Parent):
                 (sourced_code != None)
                 and
                 (sourced_comments + sourced_code != 0)
-               ):
-                self.result = float(sourced_comments) / (sourced_code + sourced_comments)
+               ): # 3-digit precision
+                self.result = float((1000 * sourced_comments) // (sourced_code + sourced_comments)) / 1000.
             else:
               self.result = 0.0
 

+ 4 - 4
metrixpp/tests/general/test_basic/test_std_lines_metrics_view_nest_per_file_stdout.gold.txt

@@ -44,7 +44,7 @@
             	std.code.lines:comments: 2
             	std.code.lines:preprocessor: 0
             	std.code.lines:total: 12
-            	std.code.ratio:comments: 0.153846153846
+            	std.code.ratio:comments: 0.153
 
 .   .   .   ./simple.cpp:26: info: Metrics per 'func' region
             	Region name    : func
@@ -183,15 +183,15 @@
 	            20 : 0.091 : 1.000 :  1	|||||||||
 
 ./simple.cpp:: info: Overall metrics for 'std.code.ratio:comments' metric
-	Average        : 0.0548951
+	Average        : 0.05481818
 	Minimum        : 0.0
 	Maximum        : 0.2
-	Total          : 0.60384615
+	Total          : 0.603
 	Distribution   : 11 regions in total (including 0 suppressed)
 	  Metric value : Ratio : R-sum : Number of regions
 	        0.0000 : 0.636 : 0.636 :  7	|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 	        0.1250 : 0.182 : 0.818 :  2	||||||||||||||||||
-	        0.1538 : 0.091 : 0.909 :  1	|||||||||
+	        0.1530 : 0.091 : 0.909 :  1	|||||||||
 	        0.2000 : 0.091 : 1.000 :  1	|||||||||
 
 

+ 5 - 5
metrixpp/tests/general/test_basic/test_std_lines_metrics_view_txt_stdout.gold.txt

@@ -54,17 +54,17 @@
 	            20 : 0.062 : 1.000 :  1	||||||
 
 ./:: info: Overall metrics for 'std.code.ratio:comments' metric
-	Average        : 0.0770261
+	Average        : 0.0769375
 	Minimum        : 0.0
-	Maximum        : 0.42857143
-	Total          : 1.23241758
+	Maximum        : 0.428
+	Total          : 1.231
 	Distribution   : 16 regions in total (including 0 suppressed)
 	  Metric value : Ratio : R-sum : Number of regions
 	        0.0000 : 0.625 : 0.625 : 10	||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 	        0.1250 : 0.125 : 0.750 :  2	||||||||||||
-	        0.1538 : 0.062 : 0.812 :  1	||||||
+	        0.1530 : 0.062 : 0.812 :  1	||||||
 	        0.2000 : 0.125 : 0.938 :  2	||||||||||||
-	        0.4286 : 0.062 : 1.000 :  1	||||||
+	        0.4280 : 0.062 : 1.000 :  1	||||||
 
 ./:: info: Directory content:
 	File           : file_deleted_in_new_sources.cpp

+ 2 - 2
metrixpp/tests/general/test_basic/test_workflow_export_default_stdout.gold.txt

@@ -1,6 +1,6 @@
 file,region,type,modified,line start,line end,std.code.complexity:cyclomatic,std.code.lines:code,std.code.lines:comments,std.code.lines:preprocessor,std.code.lines:total,std.code.ratio:comments,std.suppress:count,std.suppress:list,std.suppress.file:count,std.suppress.file:list
 ./file_deleted_in_new_sources.cpp,__global__,global,,1,34,,0,0,0,0,0.0,,,,
-./file_deleted_in_new_sources.cpp,hmm,namespace,,3,24,,4,3,0,7,0.428571428571,,,,
+./file_deleted_in_new_sources.cpp,hmm,namespace,,3,24,,4,3,0,7,0.428,,,,
 ./file_deleted_in_new_sources.cpp,B,class,,9,22,,3,0,0,3,0.0,,,,
 ./file_deleted_in_new_sources.cpp,B,function,,12,20,1,8,2,0,9,0.2,,,,
 ./file_deleted_in_new_sources.cpp,never_old,function,,26,33,1,7,0,0,7,0.0,,,,
@@ -8,7 +8,7 @@ file,region,type,modified,line start,line end,std.code.complexity:cyclomatic,std
 ./simple.cpp,__global__,global,,1,90,,0,0,0,0,0.0,,,,
 ./simple.cpp,hmm,namespace,,3,89,,4,1,1,6,0.2,,,,
 ./simple.cpp,A,class,,9,87,,20,0,0,20,0.0,,,,
-./simple.cpp,A,function,,12,23,3,11,2,0,12,0.153846153846,,,,
+./simple.cpp,A,function,,12,23,3,11,2,0,12,0.153,,,,
 ./simple.cpp,func,function,,26,40,1,5,0,0,5,0.0,,,,
 ./simple.cpp,embeded,class,,28,38,,3,0,0,3,0.0,,,,
 ./simple.cpp,embeded,function,,30,37,1,7,1,0,8,0.125,,,,

+ 3 - 3
metrixpp/tests/general/test_basic/test_workflow_export_second_stdout.gold.txt

@@ -2,17 +2,17 @@ file,region,type,modified,line start,line end,std.code.complexity:cyclomatic,std
 ./simple.cpp,__global__,global,False,1,78,,0,0,0,0,0.0,,,,
 ./simple.cpp,hmm,namespace,True,3,77,,4,1,2,7,0.2,,,,
 ./simple.cpp,A,class,True,10,75,,4,0,0,4,0.0,,,,
-./simple.cpp,A,function,False,13,24,3,11,2,0,12,0.153846153846,,,,
+./simple.cpp,A,function,False,13,24,3,11,2,0,12,0.153,,,,
 ./simple.cpp,func,function,False,26,42,1,5,0,0,5,0.0,,,,
 ./simple.cpp,embeded,class,False,28,40,,3,0,0,3,0.0,,,,
 ./simple.cpp,embeded,function,True,30,39,2,8,2,0,9,0.2,,,,
 ./simple.cpp,never,function,True,44,51,1,7,1,0,7,0.125,,,,
 ./simple.cpp,new_func,function,,53,56,0,3,1,0,4,0.25,,,,
 ./simple.cpp,new_func_complex,function,,58,62,1,5,0,0,5,0.0,,,,
-./simple.cpp,new_func_complex_but_suppressed,function,,64,72,2,8,1,0,9,0.111111111111,1,[std.code.complexity:cyclomatic],,
+./simple.cpp,new_func_complex_but_suppressed,function,,64,72,2,8,1,0,9,0.111,1,[std.code.complexity:cyclomatic],,
 ./simple.cpp,,file,True,1,78,,,,,,,,,,
 ./simple2.cpp,__global__,global,,1,26,,0,0,0,0,0.0,,,,
 ./simple2.cpp,hmm,namespace,,3,25,,4,1,0,5,0.2,,,,
 ./simple2.cpp,New_A,class,,7,23,,3,0,0,3,0.0,,,,
-./simple2.cpp,New_A,function,,10,21,3,10,2,0,12,0.166666666667,,,,
+./simple2.cpp,New_A,function,,10,21,3,10,2,0,12,0.166,,,,
 ./simple2.cpp,,file,,1,26,,,,,,,,,,

+ 3 - 3
metrixpp/tests/general/test_basic/test_workflow_view_default_stdout.gold.txt

@@ -53,13 +53,13 @@
                 </total>
             </std.code.lines>
             <std.code.ratio>
-                <comments avg="0.0770261" count="16" max="0.42857143" min="0.0" nonzero="False" sup="0" total="1.23241758">
+                <comments avg="0.0769375" count="16" max="0.428" min="0.0" nonzero="False" sup="0" total="1.231">
                     <distribution-bars>
                         <distribution-bar count="10" metric="0.0000" ratio="0.625" />
                         <distribution-bar count="2" metric="0.1250" ratio="0.125" />
-                        <distribution-bar count="1" metric="0.1538" ratio="0.0625" />
+                        <distribution-bar count="1" metric="0.1530" ratio="0.0625" />
                         <distribution-bar count="2" metric="0.2000" ratio="0.125" />
-                        <distribution-bar count="1" metric="0.4286" ratio="0.0625" />
+                        <distribution-bar count="1" metric="0.4280" ratio="0.0625" />
                     </distribution-bars>
                 </comments>
             </std.code.ratio>

+ 6 - 6
metrixpp/tests/general/test_basic/test_workflow_view_second_per_file_stdout.gold.txt

@@ -58,13 +58,13 @@
                 </total>
             </std.code.lines>
             <std.code.ratio>
-                <comments avg="0.09454157" count="11" max="0.25" min="0.0" nonzero="False" sup="0" total="1.03995726">
-                    <__diff__ avg="0.03964646" count="0" max="0.05" min="0.0" nonzero="0" sup="0" total="0.43611111" />
+                <comments avg="0.09445455" count="11" max="0.25" min="0.0" nonzero="False" sup="0" total="1.039">
+                    <__diff__ avg="0.03963636" count="0" max="0.05" min="0.0" nonzero="0" sup="0" total="0.436" />
                     <distribution-bars>
                         <distribution-bar __diff__="-2" count="5" metric="0.0000" ratio="0.45454545" />
-                        <distribution-bar __diff__="1" count="1" metric="0.1111" ratio="0.09090909" />
+                        <distribution-bar __diff__="1" count="1" metric="0.1110" ratio="0.09090909" />
                         <distribution-bar __diff__="-1" count="1" metric="0.1250" ratio="0.09090909" />
-                        <distribution-bar __diff__="0" count="1" metric="0.1538" ratio="0.09090909" />
+                        <distribution-bar __diff__="0" count="1" metric="0.1530" ratio="0.09090909" />
                         <distribution-bar __diff__="1" count="2" metric="0.2000" ratio="0.18181818" />
                         <distribution-bar __diff__="1" count="1" metric="0.2500" ratio="0.09090909" />
                     </distribution-bars>
@@ -129,7 +129,7 @@
                         <std.code.lines code="11" comments="2" preprocessor="0" total="12">
                             <__diff__ code="0" comments="0" preprocessor="0" total="0" />
                         </std.code.lines>
-                        <std.code.ratio comments="0.15384615">
+                        <std.code.ratio comments="0.153">
                             <__diff__ comments="0.0" />
                         </std.code.ratio>
                     </data>
@@ -208,7 +208,7 @@
                     <data>
                         <std.code.complexity cyclomatic="2" />
                         <std.code.lines code="8" comments="1" preprocessor="0" total="9" />
-                        <std.code.ratio comments="0.11111111" />
+                        <std.code.ratio comments="0.111" />
                         <std.suppress count="1" list="[std.code.complexity:cyclomatic]" />
                     </data>
                     <info cursor="65" line_begin="64" line_end="72" modified="None" name="new_func_complex_but_suppressed" offset_begin="649" offset_end="808" type="function" />

+ 6 - 6
metrixpp/tests/general/test_basic/test_workflow_view_second_per_file_txt_all_stdout.gold.txt

@@ -45,7 +45,7 @@
 	std.code.lines:comments: 2 [+0]
 	std.code.lines:preprocessor: 0 [+0]
 	std.code.lines:total: 12 [+0]
-	std.code.ratio:comments: 0.153846153846 [+0.0]
+	std.code.ratio:comments: 0.153 [+0.0]
 
 ./simple.cpp:26: info: Metrics per 'func' region
 	Region name    : func
@@ -135,7 +135,7 @@
 	std.code.lines:comments: 1
 	std.code.lines:preprocessor: 0
 	std.code.lines:total: 9
-	std.code.ratio:comments: 0.111111111111
+	std.code.ratio:comments: 0.111
 	std.suppress:count: 1
 	std.suppress:list: [std.code.complexity:cyclomatic]
 
@@ -206,16 +206,16 @@
 	            12 : 0.091 : 1.000 :  1 [+0 ]	|||||||||
 
 ./simple.cpp:: info: Overall metrics for 'std.code.ratio:comments' metric
-	Average        : 0.09454157 [+0.03964646]
+	Average        : 0.09445455 [+0.03963636]
 	Minimum        : 0.0 [+0.0]
 	Maximum        : 0.25 [+0.05]
-	Total          : 1.03995726 [+0.43611111]
+	Total          : 1.039 [+0.436]
 	Distribution   : 11 [+0] regions in total (including 0 [+0] suppressed)
 	  Metric value : Ratio : R-sum : Number of regions
 	        0.0000 : 0.455 : 0.455 :  5 [-2 ]	|||||||||||||||||||||||||||||||||||||||||||||
-	        0.1111 : 0.091 : 0.545 :  1 [+1 ]	|||||||||
+	        0.1110 : 0.091 : 0.545 :  1 [+1 ]	|||||||||
 	        0.1250 : 0.091 : 0.636 :  1 [-1 ]	|||||||||
-	        0.1538 : 0.091 : 0.727 :  1 [+0 ]	|||||||||
+	        0.1530 : 0.091 : 0.727 :  1 [+0 ]	|||||||||
 	        0.2000 : 0.182 : 0.909 :  2 [+1 ]	||||||||||||||||||
 	        0.2500 : 0.091 : 1.000 :  1 [+1 ]	|||||||||
 

+ 5 - 5
metrixpp/tests/general/test_basic/test_workflow_view_second_per_file_txt_new_stdout.gold.txt

@@ -45,7 +45,7 @@
 	std.code.lines:comments: 2 [+0]
 	std.code.lines:preprocessor: 0 [+0]
 	std.code.lines:total: 12 [+0]
-	std.code.ratio:comments: 0.153846153846 [+0.0]
+	std.code.ratio:comments: 0.153 [+0.0]
 
 ./simple.cpp:26: info: Metrics per 'func' region
 	Region name    : func
@@ -135,7 +135,7 @@
 	std.code.lines:comments: 1
 	std.code.lines:preprocessor: 0
 	std.code.lines:total: 9
-	std.code.ratio:comments: 0.111111111111
+	std.code.ratio:comments: 0.111
 	std.suppress:count: 1
 	std.suppress:list: [std.code.complexity:cyclomatic]
 
@@ -192,14 +192,14 @@
 	             9 : 0.333 : 1.000 : 1 [+1]	|||||||||||||||||||||||||||||||||
 
 ./simple.cpp:: info: Overall metrics for 'std.code.ratio:comments' metric
-	Average        : 0.12037037 [+0.12037037]
+	Average        : 0.12033333 [+0.12033333]
 	Minimum        : 0.0 [+0.0]
 	Maximum        : 0.25 [+0.25]
-	Total          : 0.36111111 [+0.36111111]
+	Total          : 0.361 [+0.361]
 	Distribution   : 3 [+3] regions in total (including 0 [+0] suppressed)
 	  Metric value : Ratio : R-sum : Number of regions
 	        0.0000 : 0.333 : 0.333 : 1 [+1]	|||||||||||||||||||||||||||||||||
-	        0.1111 : 0.333 : 0.667 : 1 [+1]	|||||||||||||||||||||||||||||||||
+	        0.1110 : 0.333 : 0.667 : 1 [+1]	|||||||||||||||||||||||||||||||||
 	        0.2500 : 0.333 : 1.000 : 1 [+1]	|||||||||||||||||||||||||||||||||
 
 ./simple.cpp:: info: Overall metrics for 'std.suppress:count' metric

+ 5 - 5
metrixpp/tests/general/test_basic/test_workflow_view_second_per_file_txt_touched_stdout.gold.txt

@@ -45,7 +45,7 @@
 	std.code.lines:comments: 2 [+0]
 	std.code.lines:preprocessor: 0 [+0]
 	std.code.lines:total: 12 [+0]
-	std.code.ratio:comments: 0.153846153846 [+0.0]
+	std.code.ratio:comments: 0.153 [+0.0]
 
 ./simple.cpp:26: info: Metrics per 'func' region
 	Region name    : func
@@ -135,7 +135,7 @@
 	std.code.lines:comments: 1
 	std.code.lines:preprocessor: 0
 	std.code.lines:total: 9
-	std.code.ratio:comments: 0.111111111111
+	std.code.ratio:comments: 0.111
 	std.suppress:count: 1
 	std.suppress:list: [std.code.complexity:cyclomatic]
 
@@ -201,14 +201,14 @@
 	             9 : 0.286 : 1.000 : 2 [+2]	||||||||||||||||||||||||||||
 
 ./simple.cpp:: info: Overall metrics for 'std.code.ratio:comments' metric
-	Average        : 0.1265873 [+0.06230159]
+	Average        : 0.12657143 [+0.06228571]
 	Minimum        : 0.0 [+0.0]
 	Maximum        : 0.25 [+0.05]
-	Total          : 0.88611111 [+0.43611111]
+	Total          : 0.886 [+0.436]
 	Distribution   : 7 [+0] regions in total (including 0 [+0] suppressed)
 	  Metric value : Ratio : R-sum : Number of regions
 	        0.0000 : 0.286 : 0.286 : 2 [-2]	||||||||||||||||||||||||||||
-	        0.1111 : 0.143 : 0.429 : 1 [+1]	||||||||||||||
+	        0.1110 : 0.143 : 0.429 : 1 [+1]	||||||||||||||
 	        0.1250 : 0.143 : 0.571 : 1 [-1]	||||||||||||||
 	        0.2000 : 0.286 : 0.857 : 2 [+1]	||||||||||||||||||||||||||||
 	        0.2500 : 0.143 : 1.000 : 1 [+1]	||||||||||||||

+ 5 - 5
metrixpp/tests/general/test_basic/test_workflow_view_second_stdout.gold.txt

@@ -59,14 +59,14 @@
                 </total>
             </std.code.lines>
             <std.code.ratio>
-                <comments avg="0.09377493" count="15" max="0.25" min="0.0" nonzero="False" sup="0" total="1.40662393">
-                    <__diff__ avg="0.01674883" count="-1" max="-0.17857143" min="0.0" nonzero="0" sup="0" total="0.17420635" />
+                <comments avg="0.09366667" count="15" max="0.25" min="0.0" nonzero="False" sup="0" total="1.405">
+                    <__diff__ avg="0.01672917" count="-1" max="-0.178" min="0.0" nonzero="0" sup="0" total="0.174" />
                     <distribution-bars>
                         <distribution-bar __diff__="-3" count="7" metric="0.0000" ratio="0.46666667" />
-                        <distribution-bar __diff__="1" count="1" metric="0.1111" ratio="0.06666667" />
+                        <distribution-bar __diff__="1" count="1" metric="0.1110" ratio="0.06666667" />
                         <distribution-bar __diff__="-1" count="1" metric="0.1250" ratio="0.06666667" />
-                        <distribution-bar __diff__="0" count="1" metric="0.1538" ratio="0.06666667" />
-                        <distribution-bar __diff__="1" count="1" metric="0.1667" ratio="0.06666667" />
+                        <distribution-bar __diff__="0" count="1" metric="0.1530" ratio="0.06666667" />
+                        <distribution-bar __diff__="1" count="1" metric="0.1660" ratio="0.06666667" />
                         <distribution-bar __diff__="1" count="3" metric="0.2000" ratio="0.2" />
                         <distribution-bar __diff__="1" count="1" metric="0.2500" ratio="0.06666667" />
                     </distribution-bars>

+ 6 - 6
metrixpp/tests/general/test_basic/test_workflow_view_second_txt_all_stdout.gold.txt

@@ -66,17 +66,17 @@
 	            12 : 0.133 : 1.000 :  2 [+1 ]	|||||||||||||
 
 ./:: info: Overall metrics for 'std.code.ratio:comments' metric
-	Average        : 0.09377493 [+0.01674883]
+	Average        : 0.09366667 [+0.01672917]
 	Minimum        : 0.0 [+0.0]
-	Maximum        : 0.25 [-0.17857143]
-	Total          : 1.40662393 [+0.17420635]
+	Maximum        : 0.25 [-0.178]
+	Total          : 1.405 [+0.174]
 	Distribution   : 15 [-1] regions in total (including 0 [+0] suppressed)
 	  Metric value : Ratio : R-sum : Number of regions
 	        0.0000 : 0.467 : 0.467 :  7 [-3 ]	||||||||||||||||||||||||||||||||||||||||||||||
-	        0.1111 : 0.067 : 0.533 :  1 [+1 ]	||||||
+	        0.1110 : 0.067 : 0.533 :  1 [+1 ]	||||||
 	        0.1250 : 0.067 : 0.600 :  1 [-1 ]	||||||
-	        0.1538 : 0.067 : 0.667 :  1 [+0 ]	||||||
-	        0.1667 : 0.067 : 0.733 :  1 [+1 ]	||||||
+	        0.1530 : 0.067 : 0.667 :  1 [+0 ]	||||||
+	        0.1660 : 0.067 : 0.733 :  1 [+1 ]	||||||
 	        0.2000 : 0.200 : 0.933 :  3 [+1 ]	||||||||||||||||||||
 	        0.2500 : 0.067 : 1.000 :  1 [+1 ]	||||||
 

+ 4 - 4
metrixpp/tests/general/test_basic/test_workflow_view_second_txt_new_stdout.gold.txt

@@ -59,15 +59,15 @@
 	            12 : 0.143 : 1.000 : 1 [+1]	||||||||||||||
 
 ./:: info: Overall metrics for 'std.code.ratio:comments' metric
-	Average        : 0.10396825 [+0.10396825]
+	Average        : 0.10385714 [+0.10385714]
 	Minimum        : 0.0 [+0.0]
 	Maximum        : 0.25 [+0.25]
-	Total          : 0.72777778 [+0.72777778]
+	Total          : 0.727 [+0.727]
 	Distribution   : 7 [+7] regions in total (including 0 [+0] suppressed)
 	  Metric value : Ratio : R-sum : Number of regions
 	        0.0000 : 0.429 : 0.429 : 3 [+3]	||||||||||||||||||||||||||||||||||||||||||
-	        0.1111 : 0.143 : 0.571 : 1 [+1]	||||||||||||||
-	        0.1667 : 0.143 : 0.714 : 1 [+1]	||||||||||||||
+	        0.1110 : 0.143 : 0.571 : 1 [+1]	||||||||||||||
+	        0.1660 : 0.143 : 0.714 : 1 [+1]	||||||||||||||
 	        0.2000 : 0.143 : 0.857 : 1 [+1]	||||||||||||||
 	        0.2500 : 0.143 : 1.000 : 1 [+1]	||||||||||||||
 

+ 5 - 5
metrixpp/tests/general/test_basic/test_workflow_view_second_txt_touched_stdout.gold.txt

@@ -65,16 +65,16 @@
 	            12 : 0.091 : 1.000 :  1 [+1 ]	|||||||||
 
 ./:: info: Overall metrics for 'std.code.ratio:comments' metric
-	Average        : 0.11388889 [+0.02400794]
+	Average        : 0.11381818 [+0.02398485]
 	Minimum        : 0.0 [+0.0]
-	Maximum        : 0.25 [-0.17857143]
-	Total          : 1.25277778 [+0.17420635]
+	Maximum        : 0.25 [-0.178]
+	Total          : 1.252 [+0.174]
 	Distribution   : 11 [-1] regions in total (including 0 [+0] suppressed)
 	  Metric value : Ratio : R-sum : Number of regions
 	        0.0000 : 0.364 : 0.364 :  4 [-3 ]	||||||||||||||||||||||||||||||||||||
-	        0.1111 : 0.091 : 0.455 :  1 [+1 ]	|||||||||
+	        0.1110 : 0.091 : 0.455 :  1 [+1 ]	|||||||||
 	        0.1250 : 0.091 : 0.545 :  1 [-1 ]	|||||||||
-	        0.1667 : 0.091 : 0.636 :  1 [+1 ]	|||||||||
+	        0.1660 : 0.091 : 0.636 :  1 [+1 ]	|||||||||
 	        0.2000 : 0.273 : 0.909 :  3 [+1 ]	|||||||||||||||||||||||||||
 	        0.2500 : 0.091 : 1.000 :  1 [+1 ]	|||||||||