Skip to content

Commit

Permalink
attitional tests fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
mseri committed Oct 17, 2015
1 parent 65547ff commit d0bd5e8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 86 deletions.
61 changes: 13 additions & 48 deletions src/librand/chacha.rs
Expand Up @@ -245,6 +245,7 @@ mod tests {
}

#[test]
#[rustfmt_skip]
fn test_rng_true_values() {
// Test vectors 1 and 2 from
// http://tools.ietf.org/html/draft-nir-cfrg-chacha20-poly1305-04
Expand All @@ -253,41 +254,17 @@ mod tests {

let v = (0..16).map(|_| ra.next_u32()).collect::<Vec<_>>();
assert_eq!(v,
vec!(0xade0b876,
0x903df1a0,
0xe56a5d40,
0x28bd8653,
0xb819d2bd,
0x1aed8da0,
0xccef36a8,
0xc70d778b,
0x7c5941da,
0x8d485751,
0x3fe02477,
0x374ad8b8,
0xf4b8436a,
0x1ca11815,
0x69b687c3,
0x8665eeb2));
vec!(0xade0b876, 0x903df1a0, 0xe56a5d40, 0x28bd8653,
0xb819d2bd, 0x1aed8da0, 0xccef36a8, 0xc70d778b,
0x7c5941da, 0x8d485751, 0x3fe02477, 0x374ad8b8,
0xf4b8436a, 0x1ca11815, 0x69b687c3, 0x8665eeb2));

let v = (0..16).map(|_| ra.next_u32()).collect::<Vec<_>>();
assert_eq!(v,
vec!(0xbee7079f,
0x7a385155,
0x7c97ba98,
0x0d082d73,
0xa0290fcb,
0x6965e348,
0x3e53c612,
0xed7aee32,
0x7621b729,
0x434ee69c,
0xb03371d5,
0xd539d874,
0x281fed31,
0x45fb0a51,
0x1f0ae1ac,
0x6f4d794b));
vec!(0xbee7079f, 0x7a385155, 0x7c97ba98, 0x0d082d73,
0xa0290fcb, 0x6965e348, 0x3e53c612, 0xed7aee32,
0x7621b729, 0x434ee69c, 0xb03371d5, 0xd539d874,
0x281fed31, 0x45fb0a51, 0x1f0ae1ac, 0x6f4d794b));


let seed: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7];
Expand All @@ -304,22 +281,10 @@ mod tests {
}

assert_eq!(v,
vec!(0xf225c81a,
0x6ab1be57,
0x04d42951,
0x70858036,
0x49884684,
0x64efec72,
0x4be2d186,
0x3615b384,
0x11cfa18e,
0xd3c50049,
0x75c775f6,
0x434c6530,
0x2c5bad8f,
0x898881dc,
0x5f1c86d9,
0xc1f8e7f4));
vec!(0xf225c81a, 0x6ab1be57, 0x04d42951, 0x70858036,
0x49884684, 0x64efec72, 0x4be2d186, 0x3615b384,
0x11cfa18e, 0xd3c50049, 0x75c775f6, 0x434c6530,
0x2c5bad8f, 0x898881dc, 0x5f1c86d9, 0xc1f8e7f4));
}

#[test]
Expand Down
51 changes: 13 additions & 38 deletions src/librand/isaac.rs
Expand Up @@ -591,22 +591,15 @@ mod tests {
}

#[test]
#[rustfmt_skip]
fn test_rng_32_true_values() {
let seed: &[_] = &[1, 23, 456, 7890, 12345];
let mut ra: IsaacRng = SeedableRng::from_seed(seed);
// Regression test that isaac is actually using the above vector
let v = (0..10).map(|_| ra.next_u32()).collect::<Vec<_>>();
assert_eq!(v,
vec!(2558573138,
873787463,
263499565,
2103644246,
3595684709,
4203127393,
264982119,
2765226902,
2737944514,
3900253796));
vec!(2558573138, 873787463, 263499565, 2103644246, 3595684709,
4203127393, 264982119, 2765226902, 2737944514, 3900253796));

let seed: &[_] = &[12345, 67890, 54321, 9876];
let mut rb: IsaacRng = SeedableRng::from_seed(seed);
Expand All @@ -617,33 +610,20 @@ mod tests {

let v = (0..10).map(|_| rb.next_u32()).collect::<Vec<_>>();
assert_eq!(v,
vec!(3676831399,
3183332890,
2834741178,
3854698763,
2717568474,
1576568959,
3507990155,
179069555,
141456972,
2478885421));
vec!(3676831399, 3183332890, 2834741178, 3854698763, 2717568474,
1576568959, 3507990155, 179069555, 141456972, 2478885421));
}
#[test]
#[rustfmt_skip]
fn test_rng_64_true_values() {
let seed: &[_] = &[1, 23, 456, 7890, 12345];
let mut ra: Isaac64Rng = SeedableRng::from_seed(seed);
// Regression test that isaac is actually using the above vector
let v = (0..10).map(|_| ra.next_u64()).collect::<Vec<_>>();
assert_eq!(v,
vec!(547121783600835980,
14377643087320773276,
17351601304698403469,
1238879483818134882,
11952566807690396487,
13970131091560099343,
4469761996653280935,
15552757044682284409,
6860251611068737823,
vec!(547121783600835980, 14377643087320773276, 17351601304698403469,
1238879483818134882, 11952566807690396487, 13970131091560099343,
4469761996653280935, 15552757044682284409, 6860251611068737823,
13722198873481261842));

let seed: &[_] = &[12345, 67890, 54321, 9876];
Expand All @@ -655,16 +635,11 @@ mod tests {

let v = (0..10).map(|_| rb.next_u64()).collect::<Vec<_>>();
assert_eq!(v,
vec!(18143823860592706164,
8491801882678285927,
2699425367717515619,
17196852593171130876,
2606123525235546165,
15790932315217671084,
596345674630742204,
9947027391921273664,
11788097613744130851,
vec!(18143823860592706164, 8491801882678285927, 2699425367717515619,
17196852593171130876, 2606123525235546165, 15790932315217671084,
596345674630742204, 9947027391921273664, 11788097613744130851,
10391409374914919106));

}

#[test]
Expand Down

0 comments on commit d0bd5e8

Please sign in to comment.