Skip to content

Commit

Permalink
changed minimal '/' to '⁄' such that tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
feefladder committed Jan 22, 2024
1 parent 04de0bf commit 3e3f636
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
38 changes: 19 additions & 19 deletions src/fraction/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//!
//! let fraction = Fraction::from(1.75);
//!
//! assert_eq!("7/4", format!("{}", fraction));
//! assert_eq!("74", format!("{}", fraction));
//! assert_eq!("1.75", format!("{:.4}", fraction));
//! assert_eq!("1.7500", format!("{:#.4}", fraction));
//! assert_eq!("-1.75", format!("{:.2}", -fraction));
Expand Down Expand Up @@ -592,24 +592,24 @@ mod tests {
assert_eq!("00001.75", format!("{:<-08.4}", -F32::new(7, 4)));

// ratios
assert_eq!("7/4", format!("{}", F32::new(7, 4)));
assert_eq!("7/4", format!("{:-}", F32::new(7, 4)));
assert_eq!("+7/4", format!("{:+}", F32::new(7, 4)));

assert_eq!("-7/4", format!("{}", -F32::new(7, 4)));
assert_eq!("7/4", format!("{:-}", -F32::new(7, 4)));
assert_eq!("-7/4", format!("{:+}", -F32::new(7, 4)));

assert_eq!("07/4", format!("{:04}", F32::new(7, 4)));
assert_eq!("-7/4", format!("{:+04}", -F32::new(7, 4)));

assert_eq!("==7/4==", format!("{:=^7}", F32::new(7, 4)));
assert_eq!("=-7/4==", format!("{:=^7}", -F32::new(7, 4)));
assert_eq!(" 7/4", format!("{:7}", F32::new(7, 4)));
assert_eq!("7/4 ", format!("{:<7}", F32::new(7, 4)));
assert_eq!("-7/4 ", format!("{:<7}", -F32::new(7, 4)));
assert_eq!("+7/4 ", format!("{:<+7}", F32::new(7, 4)));
assert_eq!("+0007/4", format!("{:<+07}", F32::new(7, 4)));
assert_eq!("74", format!("{}", F32::new(7, 4)));
assert_eq!("74", format!("{:-}", F32::new(7, 4)));
assert_eq!("+74", format!("{:+}", F32::new(7, 4)));

assert_eq!("-74", format!("{}", -F32::new(7, 4)));
assert_eq!("74", format!("{:-}", -F32::new(7, 4)));
assert_eq!("-74", format!("{:+}", -F32::new(7, 4)));

assert_eq!("074", format!("{:04}", F32::new(7, 4)));
assert_eq!("-74", format!("{:+04}", -F32::new(7, 4)));

assert_eq!("==74==", format!("{:=^7}", F32::new(7, 4)));
assert_eq!("=-74==", format!("{:=^7}", -F32::new(7, 4)));
assert_eq!(" 74", format!("{:7}", F32::new(7, 4)));
assert_eq!("74 ", format!("{:<7}", F32::new(7, 4)));
assert_eq!("-74 ", format!("{:<7}", -F32::new(7, 4)));
assert_eq!("+74 ", format!("{:<+7}", F32::new(7, 4)));
assert_eq!("+00074", format!("{:<+07}", F32::new(7, 4)));

// former format_as_decimal tests
assert_eq!("NaN", format!("{:.64}", F32::from(::std::f32::NAN)));
Expand Down
20 changes: 10 additions & 10 deletions src/fraction/generic_fraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ where
/// Constructs a new fraction without types casting, checking for denom == 0 and reducing numbers.
///
/// You must be careful with this function because all the other functionality parts rely on the
/// numbers to be reduced. That said, in the normal case 2/4 has to be reduced to 1/2, but it will not
/// numbers to be reduced. That said, in the normal case 24 has to be reduced to 1/2, but it will not
/// happen with new_raw.
///
/// # Examples
Expand Down Expand Up @@ -2428,11 +2428,11 @@ mod tests {
let f = GenericFraction::<$t>::from(2.0);
assert_eq!(format!("{}", f), "2");
let f = GenericFraction::<$t>::from(0.5);
assert_eq!(format!("{}", f), "1/2");
assert_eq!(format!("{}", f), "12");
let f = GenericFraction::<$t>::from(15978.649);
assert_eq!(format!("{}", f), "NaN");
let f = GenericFraction::<$t>::from(-0.75);
assert_eq!(format!("{}", f), "-3/4");
assert_eq!(format!("{}", f), "-34");
)*
};
}
Expand Down Expand Up @@ -2494,11 +2494,11 @@ mod tests {
let f = GenericFraction::<$t>::from(2.0);
assert_eq!(format!("{}", f), "2");
let f = GenericFraction::<$t>::from(0.5);
assert_eq!(format!("{}", f), "1/2");
assert_eq!(format!("{}", f), "12");
let f = GenericFraction::<$t>::from(15978.649);
assert_eq!(format!("{}", f), "15978649/1000");
assert_eq!(format!("{}", f), "159786491000");
let f = GenericFraction::<$t>::from(-0.75);
assert_eq!(format!("{}", f), "-3/4");
assert_eq!(format!("{}", f), "-34");
)*
};
}
Expand Down Expand Up @@ -2545,13 +2545,13 @@ mod tests {
let f = GenericFraction::<$t>::from(2.0);
assert_eq!(format!("{}", f), "2");
let f = GenericFraction::<$t>::from(0.5);
assert_eq!(format!("{}", f), "1/2");
assert_eq!(format!("{}", f), "12");
let f = GenericFraction::<$t>::from(15978.649);
assert_eq!(format!("{}", f), "15978649/1000");
assert_eq!(format!("{}", f), "159786491000");
let f = GenericFraction::<$t>::from(-0.75);
assert_eq!(format!("{}", f), "-3/4");
assert_eq!(format!("{}", f), "-34");
let f = GenericFraction::<$t>::from(-0.5);
assert_eq!(format!("{}", f), "-1/2");
assert_eq!(format!("{}", f), "-12");
)*
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
//! assert_eq!(F::from(2), two);
//! assert_eq!(F::new(2u64, 3u64), two_third);
//!
//! assert_eq!("2/3", format!("{}", two_third)); // print as Fraction (by default)
//! assert_eq!("23", format!("{}", two_third)); // print as Fraction (by default)
//! assert_eq!("0.6666", format!("{:.4}", two_third)); // format as decimal and print up to 4 digits after floating point
//! ```
//!
Expand Down Expand Up @@ -126,7 +126,7 @@
//! type F = fraction::Fraction;
//!
//! let result = F::from(0.7) / F::from(0.4);
//! assert_eq!(format!("{}", result), "7/4"); // Printed as fraction by default
//! assert_eq!(format!("{}", result), "74"); // Printed as fraction by default
//! assert_eq!(format!("{:.2}", result), "1.75"); // if precision is defined, printed as decimal
//! assert_eq!(format!("{:#.3}", result), "1.750"); // to print leading zeroes, pass hash to the format
//! ```
Expand Down

0 comments on commit 3e3f636

Please sign in to comment.