diff --git a/server/src/cryp.rs b/server/src/cryp.rs index c58d5276..ce2b60b2 100644 --- a/server/src/cryp.rs +++ b/server/src/cryp.rs @@ -811,7 +811,7 @@ pub fn cryp_recover(cryp_bytes: Vec, tx: &mut Transaction) -> Result u64; -} - -impl IntPct for u64 { - fn pct(self, pct: u64) -> u64 { - self * pct / 100 - } -} - impl Spec { pub fn affects(&self) -> Vec { match *self { diff --git a/server/src/util.rs b/server/src/util.rs index f278ae2c..ae1d3062 100644 --- a/server/src/util.rs +++ b/server/src/util.rs @@ -18,4 +18,27 @@ pub fn startup(db: Db) -> Result<(), Error> { }, Err(e) => Err(format_err!("failed to commit startup tx {:?}", e)), } +} + +pub trait IntPct { + fn pct(self, pct: u64) -> u64; +} + +impl IntPct for u64 { + fn pct(self, pct: u64) -> u64 { + self * pct / 100 + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn int_pct_test() { + assert_eq!(100.pct(110), 110); + assert_eq!(100.pct(50), 50); + assert_eq!(1.pct(200), 2); + assert_eq!(1.pct(50), 0); + } } \ No newline at end of file