Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/bernstein_yang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ prop_compose! {
bytes = &bytes[..32];
}

BoxedUint::from_le_slice(&bytes, 256).unwrap()
BoxedUint::from_le_slice(bytes, 256).unwrap()
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/boxed_monty_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ proptest! {
let expected = x_bi.invm(&n_bi);

match (expected, actual) {
(Some(exp), Some(act)) => prop_assert_eq!(exp, to_biguint(&act).into()),
(Some(exp), Some(act)) => prop_assert_eq!(exp, to_biguint(&act)),
(None, None) => (),
(_, _) => panic!("disagreement on if modular inverse exists")
}
Expand All @@ -107,7 +107,7 @@ proptest! {

match (expected, actual) {
(Some(exp), Some(act)) => {
prop_assert_eq!(exp, retrieve_biguint(&act).into());
prop_assert_eq!(exp, retrieve_biguint(&act));
}
(None, None) => (),
(_, _) => panic!("disagreement on if modular inverse exists")
Expand Down
45 changes: 24 additions & 21 deletions tests/boxed_uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ prop_compose! {
prop_compose! {
/// Generate a pair of random `BoxedUint`s with the same precision.
fn uint_pair()(mut a in uint(), mut b in uint()) -> (BoxedUint, BoxedUint) {
if a.bits_precision() > b.bits_precision() {
b = b.widen(a.bits_precision());
} else if a.bits_precision() < b.bits_precision() {
a = a.widen(b.bits_precision());
}

match a.bits_precision().cmp(&b.bits_precision()) {
Ordering::Greater => {
b = b.widen(a.bits_precision());
}
Ordering::Less => {
a = a.widen(b.bits_precision());
},
_ => ()
};
(a, b)
}
}
Expand All @@ -77,8 +80,8 @@ proptest! {
#[test]
fn bits(a in uint()) {
let expected = to_biguint(&a).bits() as u32;
assert_eq!(expected, a.bits());
assert_eq!(expected, a.bits_vartime());
prop_assert_eq!(expected, a.bits());
prop_assert_eq!(expected, a.bits_vartime());
}

#[test]
Expand Down Expand Up @@ -149,7 +152,7 @@ proptest! {

let expected = to_uint(f_bi.gcd(&g_bi));
let actual = f.gcd(&g);
assert_eq!(expected, actual);
prop_assert_eq!(expected, actual);
}

#[test]
Expand All @@ -166,7 +169,7 @@ proptest! {
let actual = Option::<BoxedUint>::from(a.inv_odd_mod(&b));

match (expected, actual) {
(Some(exp), Some(act)) => prop_assert_eq!(exp, to_biguint(&act).into()),
(Some(exp), Some(act)) => prop_assert_eq!(exp, to_biguint(&act)),
(None, None) => (),
(_, _) => panic!("disagreement on if modular inverse exists")
}
Expand All @@ -183,7 +186,7 @@ proptest! {

let expected = to_uint((a_bi * b_bi) % n_bi);
let actual = a.mul_mod(&b, &n);
assert_eq!(expected, actual);
prop_assert_eq!(expected, actual);
}

#[test]
Expand Down Expand Up @@ -233,10 +236,10 @@ proptest! {
let expected = to_uint((a_bi << shift as usize) & ((BigUint::one() << a.bits_precision() as usize) - BigUint::one()));
let (actual, overflow) = a.overflowing_shl(shift);

assert_eq!(expected, actual);
prop_assert_eq!(&expected, &actual);
if shift >= a.bits_precision() {
assert_eq!(actual, BoxedUint::zero());
assert!(bool::from(overflow));
prop_assert_eq!(actual, BoxedUint::zero());
prop_assert!(bool::from(overflow));
}
}

Expand All @@ -251,10 +254,10 @@ proptest! {
let actual = a.shl_vartime(shift);

if shift >= a.bits_precision() {
assert!(actual.is_none());
prop_assert!(actual.is_none());
}
else {
assert_eq!(expected, actual.unwrap());
prop_assert_eq!(expected, actual.unwrap());
}
}

Expand All @@ -268,10 +271,10 @@ proptest! {
let expected = to_uint(a_bi >> shift as usize);
let (actual, overflow) = a.overflowing_shr(shift);

assert_eq!(expected, actual);
prop_assert_eq!(&expected, &actual);
if shift >= a.bits_precision() {
assert_eq!(actual, BoxedUint::zero());
assert!(bool::from(overflow));
prop_assert_eq!(actual, BoxedUint::zero());
prop_assert!(bool::from(overflow));
}
}

Expand All @@ -287,10 +290,10 @@ proptest! {
let actual = a.shr_vartime(shift);

if shift >= a.bits_precision() {
assert!(actual.is_none());
prop_assert!(actual.is_none());
}
else {
assert_eq!(expected, actual.unwrap());
prop_assert_eq!(expected, actual.unwrap());
}
}
}
6 changes: 3 additions & 3 deletions tests/const_monty_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn retrieve_biguint(monty_form: &ConstMontyForm) -> BigUint {
}

fn reduce(n: &U256) -> ConstMontyForm {
ConstMontyForm::new(&n)
ConstMontyForm::new(n)
}

prop_compose! {
Expand All @@ -44,7 +44,7 @@ proptest! {
(Some(exp), Some(act)) => {
let res = x * act;
prop_assert_eq!(res.retrieve(), U256::ONE);
prop_assert_eq!(exp, retrieve_biguint(&act).into());
prop_assert_eq!(exp, retrieve_biguint(&act));
}
(None, None) => (),
(_, _) => panic!("disagreement on if modular inverse exists")
Expand All @@ -65,7 +65,7 @@ proptest! {
(Some(exp), Some(act)) => {
let res = x * act;
prop_assert_eq!(res.retrieve(), U256::ONE);
prop_assert_eq!(exp, retrieve_biguint(&act).into());
prop_assert_eq!(exp, retrieve_biguint(&act));
}
(None, None) => (),
(_, _) => panic!("disagreement on if modular inverse exists")
Expand Down
8 changes: 4 additions & 4 deletions tests/monty_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ proptest! {

#[test]
fn inv(x in uint(), n in modulus()) {
let x = reduce(&x, n.clone());
let x = reduce(&x, n);
let actual = Option::<MontyForm>::from(x.invert());

let x_bi = retrieve_biguint(&x);
Expand All @@ -56,7 +56,7 @@ proptest! {
(Some(exp), Some(act)) => {
let res = x * act;
prop_assert_eq!(res.retrieve(), U256::ONE);
prop_assert_eq!(exp, retrieve_biguint(&act).into());
prop_assert_eq!(exp, retrieve_biguint(&act));
}
(None, None) => (),
(_, _) => panic!("disagreement on if modular inverse exists")
Expand All @@ -65,7 +65,7 @@ proptest! {

#[test]
fn precomputed_inv(x in uint(), n in modulus()) {
let x = reduce(&x, n.clone());
let x = reduce(&x, n);
let inverter = x.params().precompute_inverter();
let actual = Option::<MontyForm>::from(inverter.invert(&x));

Expand All @@ -75,7 +75,7 @@ proptest! {

match (expected, actual) {
(Some(exp), Some(act)) => {
prop_assert_eq!(exp, retrieve_biguint(&act).into());
prop_assert_eq!(exp, retrieve_biguint(&act));
}
(None, None) => (),
(_, _) => panic!("disagreement on if modular inverse exists")
Expand Down
Loading