message: tests + trait update
diff: +use crate::Uint256;
  +
  /// A fraction `p`/`q` with integers `p` and `q`.
  ///
  /// `p` is called the numerator and `q` is called the denominator.
  @@ -13,17 +15,21 @@ pub trait Fraction<T>: Sized {
  fn inv(&self) -> Option<Self>;
  }
  -impl<T: Clone> Fraction<T> for (T, T) {
  +impl<T: Copy + Into<Uint256>> Fraction<T> for (T, T) {
  fn numerator(&self) -> T {
  - self.0.clone()
  + self.0
  }
  fn denominator(&self) -> T {
  - self.1.clone()
  + self.1
  }
  fn inv(&self) -> Option<Self> {
  - Some((self.1.clone(), self.0.clone()))
  + if self.numerator().into() == Uint256::zero() {
  + None
  + } else {
  + Some((self.1, self.0))
  + }
  }
  }
  @@ -46,13 +52,13 @@ macro_rules! impl_mul_fraction {
  self.checked_mul_floored(rhs).unwrap()
  }
  - pub fn checked_mul_ceil<F: Fraction<T> + Clone, T: Into<$Uint>>(
  + pub fn checked_mul_ceil<F: Fraction<T>, T: Into<$Uint>>(
  self,
  rhs: F,
  ) -> Result<Self, CheckedMultiplyFractionError> {
  - let floor_result = self.checked_mul_floored(rhs.clone())?;
  let numerator = rhs.numerator().into();
  let denominator = rhs.denominator().into();
  + let floor_result = self.checked_mul_floored(rhs)?;
  if !numerator.checked_rem(denominator)?.is_zero() {
  Ok($Uint::one().checked_add(floor_result)?)
  } else {
  @@ -60,9 +66,28 @@ macro_rules! impl_mul_fraction {
  }
  }
  - pub fn mul_ceil<F: Fraction<T> + Clone, T: Into<$Uint>>(self, rhs: F) -> Self {
  + pub fn mul_ceil<F: Fraction<T>, T: Into<$Uint>>(self, rhs: F) -> Self {
  self.checked_mul_ceil(rhs).unwrap()
  }
  }
  };
  }
  +
  +#[cfg(test)]
  +mod tests {
  + use crate::{Fraction, Uint128, Uint64};
  +
  + #[test]
  + fn fraction_tuple_methods() {
  + let fraction = (Uint64::one(), Uint64::new(2));
  + assert_eq!(Uint64::one(), fraction.numerator());
  + assert_eq!(Uint64::new(2), fraction.denominator());
  + assert_eq!(Some((Uint64::new(2), Uint64::one())), fraction.inv());
  + }
  +
  + #[test]
  + fn inverse_with_zero_denominator() {
  + let fraction = (Uint128::zero(), Uint128::one());
  + assert_eq!(None, fraction.inv());
  + }
  +}
  