|
| 1 | +use satoru::pricing::pricing_utils; |
| 2 | + |
| 3 | +const E20: u128 = 100_000_000_000_000_000_000; |
| 4 | +const _3: u128 = 300_000_000_000_000_000_000; |
| 5 | +const _2: u128 = 200_000_000_000_000_000_000; |
| 6 | +const _1_5: u128 = 150_000_000_000_000_000_000; |
| 7 | +const _1_75: u128 = 175_000_000_000_000_000_000; |
| 8 | +const _0_001: u128 = 100_000_000_000_000_000; |
| 9 | +const _0_0001: u128 = 10_000_000_000_000_000; |
| 10 | +const _0_000001: u128 = 1_000_000_000_000; |
| 11 | +const _0_0000000000001: u128 = 100_000_000; |
| 12 | + |
| 13 | +#[test] |
| 14 | +fn given_good_parameters_when_apply_impact_factor_then_works() { |
| 15 | + // make sure it works for really big values |
| 16 | + assert( |
| 17 | + pricing_utils::apply_impact_factor( |
| 18 | + 10000 * E20, 1 * _0_0000000000001, _3 |
| 19 | + ) == 100000000000000000000, |
| 20 | + 'wrong impact factor 1' |
| 21 | + ); |
| 22 | + assert( |
| 23 | + pricing_utils::apply_impact_factor( |
| 24 | + 100000 * E20, _0_0000000000001, _3 |
| 25 | + ) == 100000000000000000000000, |
| 26 | + 'wrong impact factor 2' |
| 27 | + ); |
| 28 | + assert( |
| 29 | + pricing_utils::apply_impact_factor( |
| 30 | + 1000000 * E20, _0_0000000000001, _3 |
| 31 | + ) == 100000000000000000000000000, |
| 32 | + 'wrong impact factor 3' |
| 33 | + ); |
| 34 | + assert( |
| 35 | + pricing_utils::apply_impact_factor( |
| 36 | + 1000000 * E20, E20, _3 |
| 37 | + ) == 100000000000000000000000000000000000000, |
| 38 | + 'wrong impact factor 4' |
| 39 | + ); |
| 40 | + |
| 41 | + assert( |
| 42 | + pricing_utils::apply_impact_factor(10000 * E20, _0_000001, _2) == 100000000000000000000, |
| 43 | + 'wrong impact factor 5' |
| 44 | + ); |
| 45 | + assert( |
| 46 | + pricing_utils::apply_impact_factor(100000 * E20, _0_000001, _2) == 10000000000000000000000, |
| 47 | + 'wrong impact factor 6' |
| 48 | + ); |
| 49 | + |
| 50 | + assert( |
| 51 | + pricing_utils::apply_impact_factor( |
| 52 | + 1000000 * E20, _0_000001, _2 |
| 53 | + ) == 1000000000000000000000000, |
| 54 | + 'wrong impact factor 7' |
| 55 | + ); |
| 56 | + assert( |
| 57 | + pricing_utils::apply_impact_factor( |
| 58 | + 10000000 * E20, _0_000001, _2 |
| 59 | + ) == 100000000000000000000000000, |
| 60 | + 'wrong impact factor 8' |
| 61 | + ); |
| 62 | + |
| 63 | + assert( |
| 64 | + pricing_utils::apply_impact_factor(10000 * E20, _0_000001, _1_75) == 9999999516460977028, |
| 65 | + 'wrong impact factor 11' |
| 66 | + ); |
| 67 | + assert( |
| 68 | + pricing_utils::apply_impact_factor(100000 * E20, _0_000001, _1_75) == 562341305085252697579, |
| 69 | + 'wrong impact factor 12' |
| 70 | + ); |
| 71 | + assert( |
| 72 | + pricing_utils::apply_impact_factor( |
| 73 | + 1000000 * E20, _0_000001, _1_75 |
| 74 | + ) == 31622775559765743614174, |
| 75 | + 'wrong impact factor 13' |
| 76 | + ); |
| 77 | + assert( |
| 78 | + pricing_utils::apply_impact_factor( |
| 79 | + 10000000 * E20, _0_000001, _1_75 |
| 80 | + ) == 1778279359983305772602558, |
| 81 | + 'wrong impact factor 14' |
| 82 | + ); |
| 83 | + |
| 84 | + // and for small values |
| 85 | + assert( |
| 86 | + pricing_utils::apply_impact_factor(_0_0000000000001, _0_000001, _1_5) == 0, |
| 87 | + 'wrong impact factor 15' |
| 88 | + ); |
| 89 | + assert( |
| 90 | + pricing_utils::apply_impact_factor(_0_001, _0_000001, _1_5) == 0, 'wrong impact factor 16' |
| 91 | + ); |
| 92 | + assert( |
| 93 | + pricing_utils::apply_impact_factor(1 * E20, _0_000001, _1_5) == 1000000000000, |
| 94 | + 'wrong impact factor 17' |
| 95 | + ); |
| 96 | + assert( |
| 97 | + pricing_utils::apply_impact_factor(1000 * E20, _0_000001, _1_5) == 31622777689150255, |
| 98 | + 'wrong impact factor 18' |
| 99 | + ); |
| 100 | + assert( |
| 101 | + pricing_utils::apply_impact_factor(10000 * E20, _0_000001, _1_5) == 999999958558642276, |
| 102 | + 'wrong impact factor 19' |
| 103 | + ); |
| 104 | + assert( |
| 105 | + pricing_utils::apply_impact_factor(100000 * E20, _0_000001, _1_5) == 31622775633373054686, |
| 106 | + 'wrong impact factor 20' |
| 107 | + ); |
| 108 | + assert( |
| 109 | + pricing_utils::apply_impact_factor(1000000 * E20, _0_000001, _1_5) == 999999971754659821919, |
| 110 | + 'wrong impact factor 21' |
| 111 | + ); |
| 112 | + assert( |
| 113 | + pricing_utils::apply_impact_factor( |
| 114 | + 10000000 * E20, _0_000001, _1_5 |
| 115 | + ) == 31622775838897949974052, |
| 116 | + 'wrong impact factor 22' |
| 117 | + ); |
| 118 | + |
| 119 | + assert( |
| 120 | + pricing_utils::apply_impact_factor(10000 * E20, _0_0001, E20) == 100000000000000000000, |
| 121 | + 'wrong impact factor 23' |
| 122 | + ); |
| 123 | + assert( |
| 124 | + pricing_utils::apply_impact_factor(100000 * E20, _0_0001, E20) == 1000000000000000000000, |
| 125 | + 'wrong impact factor 24' |
| 126 | + ); |
| 127 | + assert( |
| 128 | + pricing_utils::apply_impact_factor(1000000 * E20, _0_0001, E20) == 10000000000000000000000, |
| 129 | + 'wrong impact factor 25' |
| 130 | + ); |
| 131 | + assert( |
| 132 | + pricing_utils::apply_impact_factor( |
| 133 | + 10000000 * E20, _0_0001, E20 |
| 134 | + ) == 100000000000000000000000, |
| 135 | + 'wrong impact factor 26' |
| 136 | + ); |
| 137 | +} |
| 138 | + |
0 commit comments