about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMarcello Seri <marcello.seri@gmail.com>2015-10-16 22:47:54 +0100
committerMarcello Seri <marcello.seri@gmail.com>2015-10-16 22:47:54 +0100
commit65547ff5a2cc3c8c040302ab04cbc3bef50beec4 (patch)
tree0289f48377d0cfdcae4287b8bf4793a082a57c82 /src
parent2a59875c7281d4c0b0626ff272bae9926f990138 (diff)
downloadrust-65547ff5a2cc3c8c040302ab04cbc3bef50beec4.tar.gz
rust-65547ff5a2cc3c8c040302ab04cbc3bef50beec4.zip
Tests fixup
Diffstat (limited to 'src')
-rw-r--r--src/librand/distributions/mod.rs129
1 files changed, 29 insertions, 100 deletions
diff --git a/src/librand/distributions/mod.rs b/src/librand/distributions/mod.rs
index fd3e077917c..695933370ec 100644
--- a/src/librand/distributions/mod.rs
+++ b/src/librand/distributions/mod.rs
@@ -199,6 +199,7 @@ mod ziggurat_tables;
 /// * `pdf`: the probability density function
 /// * `zero_case`: manual sampling from the tail when we chose the
 ///    bottom box (i.e. i == 0)
+
 // the perf improvement (25-50%) is definitely worth the extra code
 // size from force-inlining.
 #[inline(always)]
@@ -297,6 +298,7 @@ mod tests {
         assert_eq!(rand_sample.ind_sample(&mut ::test::rng()), ConstRand(0));
     }
     #[test]
+    #[rustfmt_skip]
     fn test_weighted_choice() {
         // this makes assumptions about the internal implementation of
         // WeightedChoice, specifically: it doesn't reorder the items,
@@ -317,94 +319,37 @@ mod tests {
             }}
         }
 
-        t!(vec!(Weighted {
-               weight: 1,
-               item: 10,
-           }),
+        t!(vec!(Weighted { weight: 1, item: 10 }),
            [10]);
 
         // skip some
-        t!(vec!(Weighted {
-                    weight: 0,
-                    item: 20,
-                },
-                Weighted {
-                    weight: 2,
-                    item: 21,
-                },
-                Weighted {
-                    weight: 0,
-                    item: 22,
-                },
-                Weighted {
-                    weight: 1,
-                    item: 23,
-                }),
+        t!(vec!(Weighted { weight: 0, item: 20 },
+                Weighted { weight: 2, item: 21 },
+                Weighted { weight: 0, item: 22 },
+                Weighted { weight: 1, item: 23 }),
            [21, 21, 23]);
 
         // different weights
-        t!(vec!(Weighted {
-                    weight: 4,
-                    item: 30,
-                },
-                Weighted {
-                    weight: 3,
-                    item: 31,
-                }),
+        t!(vec!(Weighted { weight: 4, item: 30 },
+                Weighted { weight: 3, item: 31 }),
            [30, 30, 30, 30, 31, 31, 31]);
 
         // check that we're binary searching
         // correctly with some vectors of odd
         // length.
-        t!(vec!(Weighted {
-                    weight: 1,
-                    item: 40,
-                },
-                Weighted {
-                    weight: 1,
-                    item: 41,
-                },
-                Weighted {
-                    weight: 1,
-                    item: 42,
-                },
-                Weighted {
-                    weight: 1,
-                    item: 43,
-                },
-                Weighted {
-                    weight: 1,
-                    item: 44,
-                }),
+        t!(vec!(Weighted { weight: 1, item: 40 },
+                Weighted { weight: 1, item: 41 },
+                Weighted { weight: 1, item: 42 },
+                Weighted { weight: 1, item: 43 },
+                Weighted { weight: 1, item: 44 }),
            [40, 41, 42, 43, 44]);
-        t!(vec!(Weighted {
-                    weight: 1,
-                    item: 50,
-                },
-                Weighted {
-                    weight: 1,
-                    item: 51,
-                },
-                Weighted {
-                    weight: 1,
-                    item: 52,
-                },
-                Weighted {
-                    weight: 1,
-                    item: 53,
-                },
-                Weighted {
-                    weight: 1,
-                    item: 54,
-                },
-                Weighted {
-                    weight: 1,
-                    item: 55,
-                },
-                Weighted {
-                    weight: 1,
-                    item: 56,
-                }),
+        t!(vec!(Weighted { weight: 1, item: 50 },
+                Weighted { weight: 1, item: 51 },
+                Weighted { weight: 1, item: 52 },
+                Weighted { weight: 1, item: 53 },
+                Weighted { weight: 1, item: 54 },
+                Weighted { weight: 1, item: 55 },
+                Weighted { weight: 1, item: 56 }),
            [50, 51, 52, 53, 54, 55, 56]);
     }
 
@@ -415,35 +360,19 @@ mod tests {
     }
     #[test]
     #[should_panic]
+    #[rustfmt_skip]
     fn test_weighted_choice_zero_weight() {
-        WeightedChoice::new(&mut [Weighted {
-                                      weight: 0,
-                                      item: 0,
-                                  },
-                                  Weighted {
-                                      weight: 0,
-                                      item: 1,
-                                  }]);
+        WeightedChoice::new(&mut [Weighted { weight: 0, item: 0 },
+                                  Weighted { weight: 0, item: 1 }]);
     }
     #[test]
     #[should_panic]
+    #[rustfmt_skip]
     fn test_weighted_choice_weight_overflows() {
         let x = (!0) as usize / 2; // x + x + 2 is the overflow
-        WeightedChoice::new(&mut [Weighted {
-                                      weight: x,
-                                      item: 0,
-                                  },
-                                  Weighted {
-                                      weight: 1,
-                                      item: 1,
-                                  },
-                                  Weighted {
-                                      weight: x,
-                                      item: 2,
-                                  },
-                                  Weighted {
-                                      weight: 1,
-                                      item: 3,
-                                  }]);
+        WeightedChoice::new(&mut [Weighted { weight: x, item: 0 },
+                                  Weighted { weight: 1, item: 1 },
+                                  Weighted { weight: x, item: 2 },
+                                  Weighted { weight: 1, item: 3 }]);
     }
 }