From 3afb599568264e474da8b61a61895c121c5644e4 Mon Sep 17 00:00:00 2001 From: David Wang Date: Thu, 16 Mar 2017 08:03:29 +1100 Subject: [PATCH] Delete mini integer-division module. We no longer need this since we've added rationals. --- src/intdiv.rs | 77 --------------------------------------------------- src/lib.rs | 1 - 2 files changed, 78 deletions(-) delete mode 100644 src/intdiv.rs diff --git a/src/intdiv.rs b/src/intdiv.rs deleted file mode 100644 index e69c84d..0000000 --- a/src/intdiv.rs +++ /dev/null @@ -1,77 +0,0 @@ -//! Integer division. - -use std::i32; - -pub trait IntDiv { - fn div_round_up(self, b: Self) -> Self; - fn div_round_down(self, b: Self) -> Self; -} - -impl IntDiv for i32 { - fn div_round_up(self, b: Self) -> Self { - if b == 0 { panic!("attempt to divide by zero"); } - if b == -1 && self == i32::MIN { panic!("attempt to divide with overflow"); } - - let aa = (self as i64).abs(); - let bb = (b as i64).abs(); - if (self > 0) == (b > 0) { - ((aa + bb - 1) / bb) as i32 - } else { - -(aa / bb) as i32 - } - } - - fn div_round_down(self, b: Self) -> Self { - if b == 0 { panic!("attempt to divide by zero"); } - if b == -1 && self == i32::MIN { panic!("attempt to divide with overflow"); } - - let aa = (self as i64).abs(); - let bb = (b as i64).abs(); - if (self > 0) == (b > 0) { - (aa / bb) as i32 - } else { - -((aa + bb - 1) / bb) as i32 - } - } -} - -#[cfg(test)] -mod tests { - use std::i32; - use super::IntDiv; - - #[test] - fn test_div_round_up() { - // 7.0 / 5.0 = 1.4 - assert_eq!(( 0).div_round_up( 5), 0); - assert_eq!(( 0).div_round_up(-5), 0); - assert_eq!(( 7).div_round_up( 5), 2); - assert_eq!(( 7).div_round_up(-5), -1); - assert_eq!((-7).div_round_up( 5), -1); - assert_eq!((-7).div_round_up(-5), 2); - assert_eq!((i32::MIN).div_round_up(1), i32::MIN); - } - - #[test] - fn test_div_round_down() { - // 7.0 / 5.0 = 1.4 - assert_eq!(( 0).div_round_down( 5), 0); - assert_eq!(( 0).div_round_down(-5), 0); - assert_eq!(( 7).div_round_down( 5), 1); - assert_eq!(( 7).div_round_down(-5), -2); - assert_eq!((-7).div_round_down( 5), -2); - assert_eq!((-7).div_round_down(-5), 1); - } - - #[test] - #[should_panic] - fn test_div_round_up_panic() { - (i32::MIN).div_round_up(-1); - } - - #[test] - #[should_panic] - fn test_div_round_down_panic() { - (i32::MIN).div_round_down(-1); - } -} diff --git a/src/lib.rs b/src/lib.rs index 83f10a6..cba2bbe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,7 +49,6 @@ pub struct Solution { pub mod constraint; -mod intdiv; mod linexpr; mod puzzle;