solutions: add testcases for the minimum stuff
authorRalf Jung <post@ralfj.de>
Tue, 4 Aug 2015 11:25:17 +0000 (13:25 +0200)
committerRalf Jung <post@ralfj.de>
Tue, 4 Aug 2015 11:25:17 +0000 (13:25 +0200)
solutions/src/bigint.rs

index 8d67a78efe5267a88930302292714ccad451da89..96958b47bbe3d262804dc78ac8ec59a0fab4a37d 100644 (file)
@@ -276,7 +276,29 @@ impl ops::Sub<BigInt> for BigInt {
 #[cfg(test)]
 mod tests {
     use std::u64;
-    use super::{overflowing_add,overflowing_sub,BigInt};
+    use super::{overflowing_add,overflowing_sub,BigInt,Minimum,vec_min};
+
+    #[test]
+    fn test_min() {
+        let b1 = BigInt::new(1);
+        let b2 = BigInt::new(42);
+        let b3 = BigInt::from_vec(vec![0, 1]);
+
+        assert_eq!(b1.min(&b2), &b1);
+        assert_eq!(b3.min(&b2), &b2);
+    }
+
+    #[test]
+    fn test_vec_min() {
+    let b1 = BigInt::new(1);
+        let b2 = BigInt::new(42);
+        let b3 = BigInt::from_vec(vec![0, 1]);
+
+        assert_eq!(vec_min(&vec![b2.clone(), b1.clone(), b3.clone()]), Some(&b1));
+        assert_eq!(vec_min(&vec![b2.clone(), b3.clone()]), Some(&b2));
+        assert_eq!(vec_min(&vec![b3.clone()]), Some(&b3));
+        assert_eq!(vec_min::<BigInt>(&vec![]), None);
+    }
 
     #[test]
     fn test_overflowing_add() {