-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from artichoke/fill-bytes-eager-with-empty-re…
…mainder Do not eagerly call `next_uNN` in `fill_bytes` with empty remainder
- Loading branch information
Showing
5 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use rand_mt::Mt; | ||
|
||
// ```ruby | ||
// # Should double check this is official spec | ||
// it "returns the same numeric output for a given seed across all implementations and platforms" do | ||
// rnd = Random.new(33) | ||
// rnd.bytes(2).should == "\x14\\" | ||
// rnd.bytes(1000) # skip some | ||
// rnd.bytes(2).should == "\xA1p" | ||
// end | ||
// | ||
// it "returns the same numeric output for a given huge seed across all implementations and platforms" do | ||
// rnd = Random.new(bignum_value ** 4) | ||
// rnd.bytes(2).should == "_\x91" | ||
// rnd.bytes(1000) # skip some | ||
// rnd.bytes(2).should == "\x17\x12" | ||
// end | ||
// ``` | ||
#[test] | ||
fn spec_bytes() { | ||
let mut rng = Mt::new(33); | ||
let mut buf = [0; 2]; | ||
rng.fill_bytes(&mut buf); | ||
assert_eq!(buf[..], b"\x14\\"[..]); | ||
|
||
let mut skip = [0; 1000]; | ||
rng.fill_bytes(&mut skip); | ||
|
||
let mut buf = [0; 2]; | ||
rng.fill_bytes(&mut buf); | ||
assert_eq!(buf[..], b"\xA1p"[..]); | ||
} |