@@ -3,6 +3,7 @@ use crate::build_trace_data::build_profiler_call_trace;
33use  crate :: debugging:: { TraceArgs ,  build_debugging_trace} ; 
44use  crate :: expected_result:: { ExpectedPanicValue ,  ExpectedTestResult } ; 
55use  crate :: gas:: check_available_gas; 
6+ use  crate :: gas:: stats:: GasStats ; 
67use  crate :: package_tests:: with_config_resolved:: TestCaseWithResolvedConfig ; 
78use  crate :: running:: { RunCompleted ,  RunStatus } ; 
89use  cairo_annotations:: trace_data:: VersionedCallTrace  as  VersionedProfilerCallTrace ; 
@@ -11,21 +12,20 @@ use cheatnet::runtime_extensions::call_to_blockifier_runtime_extension::rpc::Use
1112use  cheatnet:: runtime_extensions:: forge_runtime_extension:: contracts_data:: ContractsData ; 
1213use  conversions:: byte_array:: ByteArray ; 
1314use  conversions:: felt:: ToShortString ; 
14- use  num_traits:: Pow ; 
1515use  shared:: utils:: build_readable_text; 
1616use  starknet_api:: execution_resources:: GasVector ; 
1717use  starknet_types_core:: felt:: Felt ; 
1818use  std:: fmt; 
1919use  std:: option:: Option ; 
2020
2121#[ derive( Debug ,  PartialEq ,  Clone ,  Default ) ]  
22- pub  struct  GasStatistics  { 
23-     pub  l1_gas :  GasStatisticsComponent , 
24-     pub  l1_data_gas :  GasStatisticsComponent , 
25-     pub  l2_gas :  GasStatisticsComponent , 
22+ pub  struct  GasFuzzingInfo  { 
23+     pub  l1_gas :  GasStats , 
24+     pub  l1_data_gas :  GasStats , 
25+     pub  l2_gas :  GasStats , 
2626} 
2727
28- impl  fmt:: Display  for  GasStatistics  { 
28+ impl  fmt:: Display  for  GasFuzzingInfo  { 
2929    fn  fmt ( & self ,  f :  & mut  fmt:: Formatter )  -> fmt:: Result  { 
3030        write ! ( 
3131            f, 
@@ -35,28 +35,7 @@ impl fmt::Display for GasStatistics {
3535    } 
3636} 
3737
38- #[ derive( Debug ,  PartialEq ,  Clone ,  Default ) ]  
39- pub  struct  GasStatisticsComponent  { 
40-     pub  min :  u64 , 
41-     pub  max :  u64 , 
42-     pub  mean :  f64 , 
43-     pub  std_deviation :  f64 , 
44- } 
45- 
46- impl  GasStatisticsComponent  { 
47-     #[ must_use]  
48-     pub  fn  new ( gas_usages :  & [ u64 ] )  -> Self  { 
49-         let  mean = GasStatistics :: mean ( gas_usages) ; 
50-         Self  { 
51-             min :  * gas_usages. iter ( ) . min ( ) . unwrap ( ) , 
52-             max :  * gas_usages. iter ( ) . max ( ) . unwrap ( ) , 
53-             mean, 
54-             std_deviation :  GasStatistics :: std_deviation ( mean,  gas_usages) , 
55-         } 
56-     } 
57- } 
58- 
59- impl  fmt:: Display  for  GasStatisticsComponent  { 
38+ impl  fmt:: Display  for  GasStats  { 
6039    fn  fmt ( & self ,  f :  & mut  fmt:: Formatter )  -> fmt:: Result  { 
6140        write ! ( 
6241            f, 
@@ -66,35 +45,19 @@ impl fmt::Display for GasStatisticsComponent {
6645    } 
6746} 
6847
69- impl  GasStatistics  { 
48+ impl  GasFuzzingInfo  { 
7049    #[ must_use]  
7150    pub  fn  new ( gas_usages :  & [ GasVector ] )  -> Self  { 
7251        let  l1_gas_values:  Vec < u64 >  = gas_usages. iter ( ) . map ( |gv| gv. l1_gas . 0 ) . collect ( ) ; 
7352        let  l1_data_gas_values:  Vec < u64 >  = gas_usages. iter ( ) . map ( |gv| gv. l1_data_gas . 0 ) . collect ( ) ; 
7453        let  l2_gas_values:  Vec < u64 >  = gas_usages. iter ( ) . map ( |gv| gv. l2_gas . 0 ) . collect ( ) ; 
7554
76-         GasStatistics  { 
77-             l1_gas :  {  GasStatisticsComponent :: new ( l1_gas_values. as_ref ( ) )  } , 
78-             l1_data_gas :  {  GasStatisticsComponent :: new ( l1_data_gas_values. as_ref ( ) )  } , 
79-             l2_gas :  {  GasStatisticsComponent :: new ( l2_gas_values. as_ref ( ) )  } , 
55+         GasFuzzingInfo  { 
56+             l1_gas :  {  GasStats :: new ( l1_gas_values. as_ref ( ) )  } , 
57+             l1_data_gas :  {  GasStats :: new ( l1_data_gas_values. as_ref ( ) )  } , 
58+             l2_gas :  {  GasStats :: new ( l2_gas_values. as_ref ( ) )  } , 
8059        } 
8160    } 
82- 
83-     #[ expect( clippy:: cast_precision_loss) ]  
84-     fn  mean ( gas_usages :  & [ u64 ] )  -> f64  { 
85-         let  sum:  f64  = gas_usages. iter ( ) . map ( |& x| x as  f64 ) . sum ( ) ; 
86-         sum / gas_usages. len ( )  as  f64 
87-     } 
88- 
89-     #[ expect( clippy:: cast_precision_loss) ]  
90-     fn  std_deviation ( mean :  f64 ,  gas_usages :  & [ u64 ] )  -> f64  { 
91-         let  sum_squared_diff = gas_usages
92-             . iter ( ) 
93-             . map ( |& x| ( x as  f64  - mean) . pow ( 2 ) ) 
94-             . sum :: < f64 > ( ) ; 
95- 
96-         ( sum_squared_diff / gas_usages. len ( )  as  f64 ) . sqrt ( ) 
97-     } 
9861} 
9962
10063#[ derive( Debug ,  PartialEq ,  Clone ) ]  
@@ -111,7 +74,7 @@ pub trait TestType {
11174#[ derive( Debug ,  PartialEq ,  Clone ) ]  
11275pub  struct  Fuzzing ; 
11376impl  TestType  for  Fuzzing  { 
114-     type  GasInfo  = GasStatistics ; 
77+     type  GasInfo  = GasFuzzingInfo ; 
11578    type  TestStatistics  = FuzzingStatistics ; 
11679    type  TraceData  = ( ) ; 
11780} 
@@ -240,7 +203,7 @@ impl TestCaseSummary<Fuzzing> {
240203                TestCaseSummary :: Passed  { 
241204                    name, 
242205                    msg, 
243-                     gas_info :  GasStatistics :: new ( gas_usages. as_ref ( ) ) , 
206+                     gas_info :  GasFuzzingInfo :: new ( gas_usages. as_ref ( ) ) , 
244207                    used_resources :  UsedResources :: default ( ) , 
245208                    test_statistics :  FuzzingStatistics  {  runs } , 
246209                    trace_data :  ( ) , 
@@ -495,41 +458,11 @@ impl AnyTestCaseSummary {
495458
496459#[ cfg( test) ]  
497460mod  tests { 
498-     use  super :: * ; 
499-     use  starknet_api:: execution_resources:: GasAmount ; 
461+     use  crate :: test_case_summary :: * ; 
462+     use  starknet_api:: execution_resources:: { GasAmount ,   GasVector } ; 
500463
501464    const  FLOAT_ERROR :  f64  = 0.01 ; 
502465
503-     #[ test]  
504-     fn  test_mean_basic ( )  { 
505-         let  data = [ 1 ,  2 ,  3 ,  4 ,  5 ] ; 
506-         let  result = GasStatistics :: mean ( & data) ; 
507-         assert ! ( ( result - 3.0 ) . abs( )  < FLOAT_ERROR ) ; 
508-     } 
509- 
510-     #[ test]  
511-     fn  test_mean_single_element ( )  { 
512-         let  data = [ 42 ] ; 
513-         let  result = GasStatistics :: mean ( & data) ; 
514-         assert ! ( ( result - 42.0 ) . abs( )  < FLOAT_ERROR ) ; 
515-     } 
516- 
517-     #[ test]  
518-     fn  test_std_deviation_basic ( )  { 
519-         let  data = [ 1 ,  2 ,  3 ,  4 ,  5 ] ; 
520-         let  mean_value = GasStatistics :: mean ( & data) ; 
521-         let  result = GasStatistics :: std_deviation ( mean_value,  & data) ; 
522-         assert ! ( ( result - 1.414 ) . abs( )  < FLOAT_ERROR ) ; 
523-     } 
524- 
525-     #[ test]  
526-     fn  test_std_deviation_single_element ( )  { 
527-         let  data = [ 10 ] ; 
528-         let  mean_value = GasStatistics :: mean ( & data) ; 
529-         let  result = GasStatistics :: std_deviation ( mean_value,  & data) ; 
530-         assert ! ( result. abs( )  < FLOAT_ERROR ) ; 
531-     } 
532- 
533466    #[ test]  
534467    fn  test_gas_statistics_new ( )  { 
535468        let  gas_usages = vec ! [ 
@@ -550,7 +483,7 @@ mod tests {
550483            } , 
551484        ] ; 
552485
553-         let  stats = GasStatistics :: new ( & gas_usages) ; 
486+         let  stats = GasFuzzingInfo :: new ( & gas_usages) ; 
554487
555488        assert_eq ! ( stats. l1_gas. min,  10 ) ; 
556489        assert_eq ! ( stats. l1_data_gas. min,  20 ) ; 
0 commit comments