Skip to content

Commit

Permalink
Merge pull request #3 from oprypin/random_bytes_spec
Browse files Browse the repository at this point in the history
Add spec for random_bytes generation
  • Loading branch information
ysbaddaden authored Sep 4, 2017
2 parents bc7611e + 5b8821b commit e5394d7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/std/random_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ describe "Random" do
end

describe "random_bytes" do
it "generates random bytes" do
rng = TestRNG.new([0xfa19443eu32, 1u32, 0x12345678u32])
rng.random_bytes(9).should eq Bytes[0x3e, 0x44, 0x19, 0xfa, 1, 0, 0, 0, 0x78]
rng.random_bytes(1).should eq Bytes[0x3e]
rng.random_bytes(4).should eq Bytes[1, 0, 0, 0]
rng.random_bytes(3).should eq Bytes[0x78, 0x56, 0x34]
rng.random_bytes(0).should eq Bytes.new(0)

rng = TestRNG.new([12u8, 255u8, 11u8, 5u8, 122u8, 200u8, 192u8])
rng.random_bytes(7).should eq Bytes[12, 255, 11, 5, 122, 200, 192]
end

it "gets random bytes with default number of digits" do
bytes = TestRNG.new(RNG_DATA_32).random_bytes
bytes.size.should eq(16)
Expand Down

0 comments on commit e5394d7

Please sign in to comment.