Skip to content

Commit 4c84cbc

Browse files
clean up proptest clippy warnings, asserts (#644)
Signed-off-by: Andrew Whitehead <[email protected]>
1 parent a0b43e0 commit 4c84cbc

File tree

6 files changed

+97
-94
lines changed

6 files changed

+97
-94
lines changed

tests/bernstein_yang.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ prop_compose! {
3131
bytes = &bytes[..32];
3232
}
3333

34-
BoxedUint::from_le_slice(&bytes, 256).unwrap()
34+
BoxedUint::from_le_slice(bytes, 256).unwrap()
3535
}
3636
}
3737

tests/boxed_monty_form.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ proptest! {
8989
let expected = x_bi.invm(&n_bi);
9090

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

108108
match (expected, actual) {
109109
(Some(exp), Some(act)) => {
110-
prop_assert_eq!(exp, retrieve_biguint(&act).into());
110+
prop_assert_eq!(exp, retrieve_biguint(&act));
111111
}
112112
(None, None) => (),
113113
(_, _) => panic!("disagreement on if modular inverse exists")

tests/boxed_uint.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@ prop_compose! {
4848
prop_compose! {
4949
/// Generate a pair of random `BoxedUint`s with the same precision.
5050
fn uint_pair()(mut a in uint(), mut b in uint()) -> (BoxedUint, BoxedUint) {
51-
if a.bits_precision() > b.bits_precision() {
52-
b = b.widen(a.bits_precision());
53-
} else if a.bits_precision() < b.bits_precision() {
54-
a = a.widen(b.bits_precision());
55-
}
56-
51+
match a.bits_precision().cmp(&b.bits_precision()) {
52+
Ordering::Greater => {
53+
b = b.widen(a.bits_precision());
54+
}
55+
Ordering::Less => {
56+
a = a.widen(b.bits_precision());
57+
},
58+
_ => ()
59+
};
5760
(a, b)
5861
}
5962
}
@@ -77,8 +80,8 @@ proptest! {
7780
#[test]
7881
fn bits(a in uint()) {
7982
let expected = to_biguint(&a).bits() as u32;
80-
assert_eq!(expected, a.bits());
81-
assert_eq!(expected, a.bits_vartime());
83+
prop_assert_eq!(expected, a.bits());
84+
prop_assert_eq!(expected, a.bits_vartime());
8285
}
8386

8487
#[test]
@@ -149,7 +152,7 @@ proptest! {
149152

150153
let expected = to_uint(f_bi.gcd(&g_bi));
151154
let actual = f.gcd(&g);
152-
assert_eq!(expected, actual);
155+
prop_assert_eq!(expected, actual);
153156
}
154157

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

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

184187
let expected = to_uint((a_bi * b_bi) % n_bi);
185188
let actual = a.mul_mod(&b, &n);
186-
assert_eq!(expected, actual);
189+
prop_assert_eq!(expected, actual);
187190
}
188191

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

236-
assert_eq!(expected, actual);
239+
prop_assert_eq!(&expected, &actual);
237240
if shift >= a.bits_precision() {
238-
assert_eq!(actual, BoxedUint::zero());
239-
assert!(bool::from(overflow));
241+
prop_assert_eq!(actual, BoxedUint::zero());
242+
prop_assert!(bool::from(overflow));
240243
}
241244
}
242245

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

253256
if shift >= a.bits_precision() {
254-
assert!(actual.is_none());
257+
prop_assert!(actual.is_none());
255258
}
256259
else {
257-
assert_eq!(expected, actual.unwrap());
260+
prop_assert_eq!(expected, actual.unwrap());
258261
}
259262
}
260263

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

271-
assert_eq!(expected, actual);
274+
prop_assert_eq!(&expected, &actual);
272275
if shift >= a.bits_precision() {
273-
assert_eq!(actual, BoxedUint::zero());
274-
assert!(bool::from(overflow));
276+
prop_assert_eq!(actual, BoxedUint::zero());
277+
prop_assert!(bool::from(overflow));
275278
}
276279
}
277280

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

289292
if shift >= a.bits_precision() {
290-
assert!(actual.is_none());
293+
prop_assert!(actual.is_none());
291294
}
292295
else {
293-
assert_eq!(expected, actual.unwrap());
296+
prop_assert_eq!(expected, actual.unwrap());
294297
}
295298
}
296299
}

tests/const_monty_form.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn retrieve_biguint(monty_form: &ConstMontyForm) -> BigUint {
2121
}
2222

2323
fn reduce(n: &U256) -> ConstMontyForm {
24-
ConstMontyForm::new(&n)
24+
ConstMontyForm::new(n)
2525
}
2626

2727
prop_compose! {
@@ -44,7 +44,7 @@ proptest! {
4444
(Some(exp), Some(act)) => {
4545
let res = x * act;
4646
prop_assert_eq!(res.retrieve(), U256::ONE);
47-
prop_assert_eq!(exp, retrieve_biguint(&act).into());
47+
prop_assert_eq!(exp, retrieve_biguint(&act));
4848
}
4949
(None, None) => (),
5050
(_, _) => panic!("disagreement on if modular inverse exists")
@@ -65,7 +65,7 @@ proptest! {
6565
(Some(exp), Some(act)) => {
6666
let res = x * act;
6767
prop_assert_eq!(res.retrieve(), U256::ONE);
68-
prop_assert_eq!(exp, retrieve_biguint(&act).into());
68+
prop_assert_eq!(exp, retrieve_biguint(&act));
6969
}
7070
(None, None) => (),
7171
(_, _) => panic!("disagreement on if modular inverse exists")

tests/monty_form.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ proptest! {
4545

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

5151
let x_bi = retrieve_biguint(&x);
@@ -56,7 +56,7 @@ proptest! {
5656
(Some(exp), Some(act)) => {
5757
let res = x * act;
5858
prop_assert_eq!(res.retrieve(), U256::ONE);
59-
prop_assert_eq!(exp, retrieve_biguint(&act).into());
59+
prop_assert_eq!(exp, retrieve_biguint(&act));
6060
}
6161
(None, None) => (),
6262
(_, _) => panic!("disagreement on if modular inverse exists")
@@ -65,7 +65,7 @@ proptest! {
6565

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

@@ -75,7 +75,7 @@ proptest! {
7575

7676
match (expected, actual) {
7777
(Some(exp), Some(act)) => {
78-
prop_assert_eq!(exp, retrieve_biguint(&act).into());
78+
prop_assert_eq!(exp, retrieve_biguint(&act));
7979
}
8080
(None, None) => (),
8181
(_, _) => panic!("disagreement on if modular inverse exists")

0 commit comments

Comments
 (0)