Remove multiply_by_rational (#11598)

* Removed multiply_by_rational
Replaced with multiply_by_rational_with_rounding

* fixes

* Test Fixes

* nightly fmt

* Test Fix

* Fixed fuzzer.
This commit is contained in:
Boluwatife Bakre
2022-06-17 04:57:29 +01:00
committed by GitHub
parent c47431118b
commit 0108d216d2
6 changed files with 162 additions and 147 deletions
@@ -32,8 +32,8 @@ name = "per_thing_rational"
path = "src/per_thing_rational.rs"
[[bin]]
name = "multiply_by_rational"
path = "src/multiply_by_rational.rs"
name = "multiply_by_rational_with_rounding"
path = "src/multiply_by_rational_with_rounding.rs"
[[bin]]
name = "fixed_point"
@@ -16,19 +16,21 @@
// limitations under the License.
//! # Running
//! Running this fuzzer can be done with `cargo hfuzz run multiply_by_rational`. `honggfuzz` CLI
//! options can be used by setting `HFUZZ_RUN_ARGS`, such as `-n 4` to use 4 threads.
//! Running this fuzzer can be done with `cargo hfuzz run multiply_by_rational_with_rounding`.
//! `honggfuzz` CLI options can be used by setting `HFUZZ_RUN_ARGS`, such as `-n 4` to use 4
//! threads.
//!
//! # Debugging a panic
//! Once a panic is found, it can be debugged with
//! `cargo hfuzz run-debug multiply_by_rational hfuzz_workspace/multiply_by_rational/*.fuzz`.
//! `cargo hfuzz run-debug multiply_by_rational_with_rounding
//! hfuzz_workspace/multiply_by_rational_with_rounding/*.fuzz`.
//!
//! # More information
//! More information about `honggfuzz` can be found
//! [here](https://docs.rs/honggfuzz/).
use honggfuzz::fuzz;
use sp_arithmetic::{helpers_128bit::multiply_by_rational, traits::Zero};
use sp_arithmetic::{helpers_128bit::multiply_by_rational_with_rounding, traits::Zero, Rounding};
fn main() {
loop {
@@ -42,9 +44,9 @@ fn main() {
println!("++ Equation: {} * {} / {}", a, b, c);
// The point of this fuzzing is to make sure that `multiply_by_rational` is 100%
// accurate as long as the value fits in a u128.
if let Ok(result) = multiply_by_rational(a, b, c) {
// The point of this fuzzing is to make sure that `multiply_by_rational_with_rounding`
// is 100% accurate as long as the value fits in a u128.
if let Some(result) = multiply_by_rational_with_rounding(a, b, c, Rounding::Down) {
let truth = mul_div(a, b, c);
if result != truth && result != truth + 1 {