Skip to content
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 clippy lints on tests #318

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 12 additions & 14 deletions tests/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ fn test_cmp() {
let vs: [&[u32]; 4] = [&[2_u32], &[1, 1], &[2, 1], &[1, 1, 1]];
let mut nums = Vec::new();
for s in vs.iter().rev() {
nums.push(BigInt::from_slice(Minus, *s));
nums.push(BigInt::from_slice(Minus, s));
}
nums.push(Zero::zero());
nums.extend(vs.iter().map(|s| BigInt::from_slice(Plus, *s)));
nums.extend(vs.iter().map(|s| BigInt::from_slice(Plus, s)));

for (i, ni) in nums.iter().enumerate() {
for (j0, nj) in nums[i..].iter().enumerate() {
Expand All @@ -199,26 +199,26 @@ fn test_cmp() {
assert_eq!(ni.cmp(nj), Equal);
assert_eq!(nj.cmp(ni), Equal);
assert_eq!(ni, nj);
assert!(!(ni != nj));
assert!((ni == nj));
assert!(ni <= nj);
assert!(ni >= nj);
assert!(!(ni < nj));
assert!(!(ni > nj));
assert!((ni >= nj));
assert!((ni <= nj));
} else {
assert_eq!(ni.cmp(nj), Less);
assert_eq!(nj.cmp(ni), Greater);

assert!(!(ni == nj));
assert!((ni != nj));
assert!(ni != nj);

assert!(ni <= nj);
assert!(!(ni >= nj));
assert!((ni < nj));
assert!(ni < nj);
assert!(!(ni > nj));
assert!((ni <= nj));

assert!(!(nj <= ni));
assert!((nj > ni));
assert!(nj >= ni);
assert!(!(nj < ni));
assert!((nj >= ni));
assert!(nj > ni);
}
}
Expand Down Expand Up @@ -1217,9 +1217,7 @@ fn test_from_str_radix() {

// issue 10522, this hit an edge case that caused it to
// attempt to allocate a vector of size (-1u) == huge.
let x: BigInt = format!("1{}", repeat("0").take(36).collect::<String>())
.parse()
.unwrap();
let x: BigInt = format!("1{}", "0".repeat(36)).parse().unwrap();
let _y = x.to_string();
}

Expand Down Expand Up @@ -1318,7 +1316,7 @@ fn test_iter_product() {
FromPrimitive::from_i32(-1004).unwrap(),
FromPrimitive::from_i32(1005).unwrap(),
];
let result = data.get(0).unwrap()
let result = data.first().unwrap()
* data.get(1).unwrap()
* data.get(2).unwrap()
* data.get(3).unwrap()
Expand Down
12 changes: 6 additions & 6 deletions tests/bigint_bitwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use crate::ValueVec::*;

impl ToBigInt for ValueVec {
fn to_bigint(&self) -> Option<BigInt> {
match self {
&N => Some(BigInt::from_slice(Sign::NoSign, &[])),
&P(s) => Some(BigInt::from_slice(Sign::Plus, s)),
&M(s) => Some(BigInt::from_slice(Sign::Minus, s)),
match *self {
N => Some(BigInt::from_slice(Sign::NoSign, &[])),
P(s) => Some(BigInt::from_slice(Sign::Plus, s)),
M(s) => Some(BigInt::from_slice(Sign::Minus, s)),
}
}
}
Expand Down Expand Up @@ -106,7 +106,7 @@ const I64_VALUES: &[i64] = &[

#[test]
fn test_not() {
for &(ref a, ref not) in NOT_VALUES.iter() {
for (a, not) in NOT_VALUES.iter() {
let a = a.to_bigint().unwrap();
let not = not.to_bigint().unwrap();

Expand All @@ -131,7 +131,7 @@ fn test_not_i64() {

#[test]
fn test_bitwise() {
for &(ref a, ref b, ref and, ref or, ref xor) in BITWISE_VALUES.iter() {
for (a, b, and, or, xor) in BITWISE_VALUES.iter() {
let a = a.to_bigint().unwrap();
let b = b.to_bigint().unwrap();
let and = and.to_bigint().unwrap();
Expand Down
58 changes: 23 additions & 35 deletions tests/biguint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,34 +90,34 @@ fn test_to_bytes_le() {
#[test]
fn test_cmp() {
let data: [&[_]; 7] = [&[], &[1], &[2], &[!0], &[0, 1], &[2, 1], &[1, 1, 1]];
let data: Vec<BigUint> = data.iter().map(|v| BigUint::from_slice(*v)).collect();
let data: Vec<BigUint> = data.iter().map(|v| BigUint::from_slice(v)).collect();
for (i, ni) in data.iter().enumerate() {
for (j0, nj) in data[i..].iter().enumerate() {
let j = j0 + i;
if i == j {
assert_eq!(ni.cmp(nj), Equal);
assert_eq!(nj.cmp(ni), Equal);
assert_eq!(ni, nj);
assert!(!(ni != nj));
assert!((ni == nj));
assert!(ni <= nj);
assert!(ni >= nj);
assert!(!(ni < nj));
assert!(!(ni > nj));
assert!((ni >= nj));
assert!((ni <= nj));
} else {
assert_eq!(ni.cmp(nj), Less);
assert_eq!(nj.cmp(ni), Greater);

assert!(!(ni == nj));
assert!((ni != nj));
assert!(ni != nj);

assert!(ni <= nj);
assert!(!(ni >= nj));
assert!((ni < nj));
assert!(ni < nj);
assert!(!(ni > nj));
assert!((ni <= nj));

assert!(!(nj <= ni));
assert!((nj > ni));
assert!(nj >= ni);
assert!(!(nj < ni));
assert!((nj >= ni));
assert!(nj > ni);
}
}
Expand Down Expand Up @@ -146,6 +146,7 @@ fn test_hash() {
}

// LEFT, RIGHT, AND, OR, XOR
#[allow(clippy::type_complexity)]
const BIT_TESTS: &[(&[u32], &[u32], &[u32], &[u32], &[u32])] = &[
(&[], &[], &[], &[], &[]),
(&[1, 0, 1], &[1, 1], &[1], &[1, 1, 1], &[0, 1, 1]),
Expand Down Expand Up @@ -1220,14 +1221,8 @@ fn to_str_pairs() -> Vec<(BigUint, Vec<(u32, String)>)> {
(
BigUint::from_slice(&[1, 2]),
vec![
(
2,
format!("10{}1", repeat("0").take(bits - 1).collect::<String>()),
),
(
4,
format!("2{}1", repeat("0").take(bits / 2 - 1).collect::<String>()),
),
(2, format!("10{}1", "0".repeat(bits - 1))),
(4, format!("2{}1", "0".repeat(bits / 2 - 1))),
(
10,
match bits {
Expand All @@ -1237,29 +1232,22 @@ fn to_str_pairs() -> Vec<(BigUint, Vec<(u32, String)>)> {
_ => panic!(),
},
),
(
16,
format!("2{}1", repeat("0").take(bits / 4 - 1).collect::<String>()),
),
(16, format!("2{}1", "0".repeat(bits / 4 - 1))),
],
),
(
BigUint::from_slice(&[1, 2, 3]),
vec![
(
2,
format!(
"11{}10{}1",
repeat("0").take(bits - 2).collect::<String>(),
repeat("0").take(bits - 1).collect::<String>()
),
format!("11{}10{}1", "0".repeat(bits - 2), "0".repeat(bits - 1)),
),
(
4,
format!(
"3{}2{}1",
repeat("0").take(bits / 2 - 1).collect::<String>(),
repeat("0").take(bits / 2 - 1).collect::<String>()
"0".repeat(bits / 2 - 1),
"0".repeat(bits / 2 - 1)
),
),
(
Expand All @@ -1284,8 +1272,8 @@ fn to_str_pairs() -> Vec<(BigUint, Vec<(u32, String)>)> {
16,
format!(
"3{}2{}1",
repeat("0").take(bits / 4 - 1).collect::<String>(),
repeat("0").take(bits / 4 - 1).collect::<String>()
"0".repeat(bits / 4 - 1),
"0".repeat(bits / 4 - 1)
),
),
],
Expand All @@ -1297,9 +1285,9 @@ fn to_str_pairs() -> Vec<(BigUint, Vec<(u32, String)>)> {
fn test_to_str_radix() {
let r = to_str_pairs();
for num_pair in r.iter() {
let &(ref n, ref rs) = num_pair;
let (n, rs) = num_pair;
for str_pair in rs.iter() {
let &(ref radix, ref str) = str_pair;
let (radix, str) = str_pair;
assert_eq!(n.to_str_radix(*radix), *str);
}
}
Expand Down Expand Up @@ -1630,9 +1618,9 @@ fn test_from_and_to_radix() {
fn test_from_str_radix() {
let r = to_str_pairs();
for num_pair in r.iter() {
let &(ref n, ref rs) = num_pair;
let (n, rs) = num_pair;
for str_pair in rs.iter() {
let &(ref radix, ref str) = str_pair;
let (radix, str) = str_pair;
assert_eq!(n, &BigUint::from_str_radix(str, *radix).unwrap());
}
}
Expand Down Expand Up @@ -1800,7 +1788,7 @@ fn test_iter_product() {
FromPrimitive::from_u32(1004).unwrap(),
FromPrimitive::from_u32(1005).unwrap(),
];
let result = data.get(0).unwrap()
let result = data.first().unwrap()
* data.get(1).unwrap()
* data.get(2).unwrap()
* data.get(3).unwrap()
Expand Down
1 change: 1 addition & 0 deletions tests/consts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub const MUL_TRIPLES: &[(&[u32], &[u32], &[u32])] = &[
(&[0, 0, 1], &[0, 0, 0, 1], &[0, 0, 0, 0, 0, 1]),
];

#[allow(clippy::type_complexity)]
pub const DIV_REM_QUADRUPLES: &[(&[u32], &[u32], &[u32], &[u32])] = &[
(&[1], &[2], &[], &[1]),
(&[3], &[2], &[1], &[1]),
Expand Down