This commit is contained in:
ntr 2019-05-01 12:00:18 +10:00
parent 3ac4fd6d1b
commit 2dfdd0d09c
3 changed files with 25 additions and 11 deletions

View File

@ -811,7 +811,7 @@ pub fn cryp_recover(cryp_bytes: Vec<u8>, tx: &mut Transaction) -> Result<Cryp, E
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use cryp::*; use cryp::*;
use spec::IntPct; use util::IntPct;
#[test] #[test]
fn create_cryp_test() { fn create_cryp_test() {

View File

@ -1,4 +1,5 @@
use cryp::{Stat, Colours}; use cryp::{Stat, Colours};
use util::{IntPct};
#[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq,PartialOrd,Ord,Eq)] #[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq,PartialOrd,Ord,Eq)]
pub enum Spec { pub enum Spec {
@ -28,16 +29,6 @@ pub enum Spec {
RBDI, RBDI,
} }
pub trait IntPct {
fn pct(self, pct: u64) -> u64;
}
impl IntPct for u64 {
fn pct(self, pct: u64) -> u64 {
self * pct / 100
}
}
impl Spec { impl Spec {
pub fn affects(&self) -> Vec<Stat> { pub fn affects(&self) -> Vec<Stat> {
match *self { match *self {

View File

@ -18,4 +18,27 @@ pub fn startup(db: Db) -> Result<(), Error> {
}, },
Err(e) => Err(format_err!("failed to commit startup tx {:?}", e)), 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);
}
} }