Skip to content

Commit

Permalink
Convert std::rand::Rng::gen_iter to sample_iter
Browse files Browse the repository at this point in the history
  • Loading branch information
chalharu committed May 26, 2018
1 parent 16764ae commit 6c3acc9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -23,7 +23,7 @@ cfg-if = ">0.0.0"

[dev-dependencies]
simple_logger = { version = ">=0.0.0" }
rand = ">=0.0.0"
rand = ">=0.5.0"

[features]
default = [ "std", "bzip2", "gzip", "deflate", "zlib" ]
Expand Down
9 changes: 5 additions & 4 deletions src/deflate/mod.rs
Expand Up @@ -130,6 +130,7 @@ mod tests {
use deflate::decoder::Deflater;
use deflate::encoder::Inflater;
use rand::{Rng, SeedableRng, XorShiftRng};
use rand::distributions::Standard;
use traits::decoder::DecodeExt;
use traits::encoder::EncodeExt;

Expand Down Expand Up @@ -185,7 +186,7 @@ mod tests {
0x51, 0x6D, 0x3E, 0xA2, 0xF3,
]);

check(&(rng.gen_iter().take(323_742).collect::<Vec<_>>()));
check(&(rng.sample_iter(&Standard).take(323_742).collect::<Vec<_>>()));
}

#[test]
Expand All @@ -195,7 +196,7 @@ mod tests {
0x51, 0x6D, 0x3E, 0xA2, 0xF3,
]);

check(&(rng.gen_iter().take(323_742).collect::<Vec<_>>()));
check(&(rng.sample_iter(&Standard).take(323_742).collect::<Vec<_>>()));
}

#[test]
Expand All @@ -206,7 +207,7 @@ mod tests {
]);

check(
&(rng.gen_iter()
&(rng.sample_iter(&Standard)
.take(0xF_FFFF)
.collect::<Vec<_>>()),
);
Expand All @@ -218,7 +219,7 @@ mod tests {
0x51, 0x6D, 0x3E, 0xA2, 0xF3,
]);

check(&(rng.gen_iter().take(len).collect::<Vec<_>>()));
check(&(rng.sample_iter(&Standard).take(len).collect::<Vec<_>>()));
}

#[test]
Expand Down
9 changes: 5 additions & 4 deletions src/gzip/mod.rs
Expand Up @@ -17,6 +17,7 @@ mod tests {
use gzip::decoder::GZipDecoder;
use gzip::encoder::GZipEncoder;
use rand::{Rng, SeedableRng, XorShiftRng};
use rand::distributions::Standard;
use traits::decoder::DecodeExt;
use traits::encoder::EncodeExt;

Expand Down Expand Up @@ -72,7 +73,7 @@ mod tests {
0x51, 0x6D, 0x3E, 0xA2, 0xF3,
]);

check(&(rng.gen_iter().take(323_742).collect::<Vec<_>>()));
check(&(rng.sample_iter(&Standard).take(323_742).collect::<Vec<_>>()));
}

#[test]
Expand All @@ -82,7 +83,7 @@ mod tests {
0x51, 0x6D, 0x3E, 0xA2, 0xF3,
]);

check(&(rng.gen_iter().take(323_742).collect::<Vec<_>>()));
check(&(rng.sample_iter(&Standard).take(323_742).collect::<Vec<_>>()));
}

#[test]
Expand All @@ -93,7 +94,7 @@ mod tests {
]);

check(
&(rng.gen_iter()
&(rng.sample_iter(&Standard)
.take(0xF_FFFF)
.collect::<Vec<_>>()),
);
Expand All @@ -105,7 +106,7 @@ mod tests {
0x51, 0x6D, 0x3E, 0xA2, 0xF3,
]);

check(&(rng.gen_iter().take(len).collect::<Vec<_>>()));
check(&(rng.sample_iter(&Standard).take(len).collect::<Vec<_>>()));
}

#[test]
Expand Down
9 changes: 5 additions & 4 deletions src/lzhuf/mod.rs
Expand Up @@ -45,6 +45,7 @@ mod tests {
use lzhuf::decoder::LzhufDecoder;
use lzhuf::encoder::LzhufEncoder;
use rand::{Rng, SeedableRng, XorShiftRng};
use rand::distributions::Standard;
use traits::decoder::DecodeExt;
use traits::encoder::EncodeExt;

Expand Down Expand Up @@ -101,7 +102,7 @@ mod tests {
0x51, 0x6D, 0x3E, 0xA2, 0xF3,
]);

check(&(rng.gen_iter().take(323_742).collect::<Vec<_>>()));
check(&(rng.sample_iter(&Standard).take(323_742).collect::<Vec<_>>()));
}

#[test]
Expand All @@ -111,7 +112,7 @@ mod tests {
0x51, 0x6D, 0x3E, 0xA2, 0xF3,
]);

check(&(rng.gen_iter().take(323_742).collect::<Vec<_>>()));
check(&(rng.sample_iter(&Standard).take(323_742).collect::<Vec<_>>()));
}

#[test]
Expand All @@ -122,7 +123,7 @@ mod tests {
]);

check(
&(rng.gen_iter()
&(rng.sample_iter(&Standard)
.take(0xF_FFFF)
.collect::<Vec<_>>()),
);
Expand All @@ -134,7 +135,7 @@ mod tests {
0x51, 0x6D, 0x3E, 0xA2, 0xF3,
]);

check(&(rng.gen_iter().take(len).collect::<Vec<_>>()));
check(&(rng.sample_iter(&Standard).take(len).collect::<Vec<_>>()));
}

#[test]
Expand Down
9 changes: 5 additions & 4 deletions src/zlib/mod.rs
Expand Up @@ -15,6 +15,7 @@ mod tests {
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use rand::{Rng, SeedableRng, XorShiftRng};
use rand::distributions::Standard;
use traits::decoder::DecodeExt;
use traits::encoder::EncodeExt;
use zlib::decoder::ZlibDecoder;
Expand Down Expand Up @@ -72,7 +73,7 @@ mod tests {
0x51, 0x6D, 0x3E, 0xA2, 0xF3,
]);

check(&(rng.gen_iter().take(323_742).collect::<Vec<_>>()));
check(&(rng.sample_iter(&Standard).take(323_742).collect::<Vec<_>>()));
}

#[test]
Expand All @@ -82,7 +83,7 @@ mod tests {
0x51, 0x6D, 0x3E, 0xA2, 0xF3,
]);

check(&(rng.gen_iter().take(323_742).collect::<Vec<_>>()));
check(&(rng.sample_iter(&Standard).take(323_742).collect::<Vec<_>>()));
}

#[test]
Expand All @@ -93,7 +94,7 @@ mod tests {
]);

check(
&(rng.gen_iter()
&(rng.sample_iter(&Standard)
.take(0xF_FFFF)
.collect::<Vec<_>>()),
);
Expand All @@ -105,7 +106,7 @@ mod tests {
0x51, 0x6D, 0x3E, 0xA2, 0xF3,
]);

check(&(rng.gen_iter().take(len).collect::<Vec<_>>()));
check(&(rng.sample_iter(&Standard).take(len).collect::<Vec<_>>()));
}

#[test]
Expand Down

0 comments on commit 6c3acc9

Please sign in to comment.