-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix test_uint32_shr failing on debug builds. #98
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,7 +175,7 @@ impl UInt32 { | |
} | ||
|
||
pub fn shr(&self, by: usize) -> Self { | ||
let by = by % 32; | ||
assert!(by < 32); | ||
|
||
let fill = Boolean::constant(false); | ||
|
||
|
@@ -656,7 +656,7 @@ mod test { | |
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); | ||
|
||
for _ in 0..50 { | ||
for i in 0..60 { | ||
for i in 0..32 { | ||
let num = rng.gen(); | ||
let a = UInt32::constant(num).shr(i); | ||
let b = UInt32::constant(num >> i); | ||
|
@@ -671,6 +671,19 @@ mod test { | |
} | ||
} | ||
|
||
#[test] | ||
fn test_uint32_shr_overflow() { | ||
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); | ||
|
||
for _ in 0..50 { | ||
for i in 32..60 { | ||
let num = rng.gen(); | ||
let result = std::panic::catch_unwind(|| UInt32::constant(num).shr(i)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a better approach is using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't do that because I wanted the test to make sure it panics on a bunch of different values, whereas |
||
assert!(result.is_err()); | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_uint32_sha256_maj() { | ||
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0653]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really needed to do this 50 times? The behaviour is easily seen from the source to not be value-dependent.