@@ -6,6 +6,33 @@ use crate::{
66use soroban_sdk:: { Address , Env , String } ;
77use soroban_sdk:: testutils:: Address as _;
88
9+ #[ test]
10+ fn test_fixed_point_zero_division_protection ( ) {
11+ // Test calculate_avg_rating with zero review count
12+ let avg = crate :: fixed_point:: calculate_avg_rating ( 15000 , 0 ) ;
13+ assert_eq ! ( avg, 0 ) ; // Should return 0 instead of panicking
14+
15+ // Test safe_div_bps with zero denominator
16+ let result = crate :: fixed_point:: safe_div_bps ( 10000 , 0 ) ;
17+ assert_eq ! ( result, 0 ) ; // Should return 0 instead of panicking
18+
19+ // Test bps_multiply with zero scale
20+ let result = crate :: fixed_point:: bps_multiply ( 5000 , 2 , 0 ) ;
21+ assert_eq ! ( result, 0 ) ; // Should return 0 instead of panicking
22+
23+ // Test calculate_avg_rating with valid inputs
24+ let avg = crate :: fixed_point:: calculate_avg_rating ( 15000 , 3 ) ;
25+ assert_eq ! ( avg, 5000 ) ; // 15000/3 = 5000
26+
27+ // Test safe_div_bps with valid inputs
28+ let result = crate :: fixed_point:: safe_div_bps ( 5000 , 2 ) ;
29+ assert_eq ! ( result, 2500 ) ; // 5000/2 = 2500
30+
31+ // Test bps_multiply with valid inputs
32+ let result = crate :: fixed_point:: bps_multiply ( 5000 , 2 , 10000 ) ;
33+ assert_eq ! ( result, 1 ) ; // (5000*2)/10000 = 1
34+ }
35+
936#[ test]
1037fn test_initialize ( ) {
1138 let env = Env :: default ( ) ;
0 commit comments