Skip to content

Commit ad7ec45

Browse files
authored
Fix Clippy warings (#468)
1 parent 010ad3a commit ad7ec45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+206
-230
lines changed

src/big_integer/poly1305.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ mod tests {
9191
mac.add_msg(&tmp_buffer, 2);
9292
let result = mac.get_tag();
9393
assert_eq!(
94-
get_tag_hex(&result.as_slice()),
94+
get_tag_hex(result.as_slice()),
9595
"a8061dc1305136c6c22b8baf0c0127a9"
9696
);
9797
}

src/ciphers/aes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ mod tests {
538538
let decrypted = aes_decrypt(&encrypted, AesKey::AesKey128(key));
539539
assert_eq!(
540540
str,
541-
String::from_utf8(decrypted).unwrap().trim_end_matches("\0")
541+
String::from_utf8(decrypted).unwrap().trim_end_matches('\0')
542542
);
543543
}
544544
}

src/ciphers/diffie_hellman.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -296,24 +296,20 @@ mod tests {
296296
#[test]
297297
fn verify_invalid_pub_key() {
298298
let diffie = DiffieHellman::new(Some(14));
299-
assert_eq!(diffie.is_valid_public_key("0000"), false);
299+
assert!(!diffie.is_valid_public_key("0000"));
300300
}
301301

302302
#[test]
303303
fn verify_valid_pub_key() {
304304
let diffie = DiffieHellman::new(Some(14));
305-
assert_eq!(
306-
diffie.is_valid_public_key("EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"),
307-
true
308-
);
305+
assert!(diffie.is_valid_public_key("EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"));
309306
}
310307

311308
#[test]
312309
fn verify_invalid_pub_key_same_as_prime() {
313310
let diffie = DiffieHellman::new(Some(14));
314-
assert_eq!(
315-
diffie.is_valid_public_key(
316-
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1\
311+
assert!(!diffie.is_valid_public_key(
312+
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1\
317313
29024E088A67CC74020BBEA63B139B22514A08798E3404DD\
318314
EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245\
319315
E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED\
@@ -324,9 +320,7 @@ mod tests {
324320
E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9\
325321
DE2BCBF6955817183995497CEA956AE515D2261898FA0510\
326322
15728E5A8AACAA68FFFFFFFFFFFFFFFF"
327-
),
328-
false
329-
);
323+
));
330324
}
331325

332326
#[test]

src/ciphers/hashing_traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ mod tests {
7979
// echo -n "Hello World" | openssl sha256 -hex -mac HMAC -macopt hexkey:"deadbeef"
8080
let mut hmac: HMAC<64, 32, SHA256> = HMAC::new_default();
8181
hmac.add_key(&[0xde, 0xad, 0xbe, 0xef]).unwrap();
82-
hmac.update(&b"Hello World".to_vec());
82+
hmac.update(b"Hello World");
8383
let hash = hmac.finalize();
8484
assert_eq!(
8585
get_hash_string(&hash),

src/ciphers/morse_code.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ pub fn encode(message: &str) -> String {
88
let dictionary = _morse_dictionary();
99
message
1010
.chars()
11-
.into_iter()
1211
.map(|char| char.to_uppercase().to_string())
1312
.map(|letter| dictionary.get(letter.as_str()))
1413
.map(|option| option.unwrap_or(&UNKNOWN_CHARACTER).to_string())
1514
.collect::<Vec<String>>()
1615
.join(" ")
1716
}
1817

19-
// Declaritive macro for creating readable map declarations, for more info see https://doc.rust-lang.org/book/ch19-06-macros.html
18+
// Declarative macro for creating readable map declarations, for more info see https://doc.rust-lang.org/book/ch19-06-macros.html
2019
macro_rules! map {
2120
($($key:expr => $value:expr),* $(,)?) => {
2221
std::iter::Iterator::collect(IntoIterator::into_iter([$(($key, $value),)*]))

src/ciphers/sha256.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ pub mod tests {
270270
#[test]
271271
fn ascii() {
272272
let mut res = SHA256::new_default();
273-
res.update(&b"The quick brown fox jumps over the lazy dog".to_vec());
273+
res.update(b"The quick brown fox jumps over the lazy dog");
274274
assert_eq!(
275275
res.get_hash(),
276276
[
@@ -284,7 +284,7 @@ pub mod tests {
284284
#[test]
285285
fn ascii_avalanche() {
286286
let mut res = SHA256::new_default();
287-
res.update(&b"The quick brown fox jumps over the lazy dog.".to_vec());
287+
res.update(b"The quick brown fox jumps over the lazy dog.");
288288
assert_eq!(
289289
res.get_hash(),
290290
[
@@ -306,7 +306,7 @@ pub mod tests {
306306
#[test]
307307
fn long_ascii() {
308308
let mut res = SHA256::new_default();
309-
let val = &b"The quick brown fox jumps over the lazy dog.".to_vec();
309+
let val = b"The quick brown fox jumps over the lazy dog.";
310310
for _ in 0..1000 {
311311
res.update(val);
312312
}
@@ -316,7 +316,7 @@ pub mod tests {
316316
"c264fca077807d391df72fadf39dd63be21f1823f65ca530c9637760eabfc18c"
317317
);
318318
let mut res = SHA256::new_default();
319-
let val = &b"a".to_vec();
319+
let val = b"a";
320320
for _ in 0..999 {
321321
res.update(val);
322322
}
@@ -329,7 +329,7 @@ pub mod tests {
329329
#[test]
330330
fn short_ascii() {
331331
let mut res = SHA256::new_default();
332-
let val = &b"a".to_vec();
332+
let val = b"a";
333333
res.update(val);
334334
let hash = res.get_hash();
335335
assert_eq!(

src/ciphers/xor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ mod tests {
3535
#[test]
3636
fn test_zero_byte() {
3737
let test_string = "The quick brown fox jumps over the lazy dog";
38-
let key = ' ' as u8;
38+
let key = b' ';
3939
let ciphered_text = xor(test_string, key);
4040
assert_eq!(test_string.as_bytes(), xor_bytes(&ciphered_text, key));
4141
}
4242

4343
#[test]
4444
fn test_invalid_byte() {
4545
let test_string = "The quick brown fox jumps over the lazy dog";
46-
let key = !0 as u8;
46+
let key = !0;
4747
let ciphered_text = xor(test_string, key);
4848
assert_eq!(test_string.as_bytes(), xor_bytes(&ciphered_text, key));
4949
}

src/data_structures/avl_tree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ mod tests {
365365
#[test]
366366
fn sorted() {
367367
let tree: AVLTree<_> = (1..8).rev().collect();
368-
assert!((1..8).eq(tree.iter().map(|&x| x)));
368+
assert!((1..8).eq(tree.iter().copied()));
369369
}
370370

371371
#[test]

src/data_structures/b_tree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,6 @@ mod test {
182182
tree.insert(12);
183183
tree.insert(15);
184184
assert!(tree.search(15));
185-
assert_eq!(tree.search(16), false);
185+
assert!(!tree.search(16));
186186
}
187187
}

src/data_structures/graph.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ mod test_undirected_graph {
135135
(&String::from("c"), &String::from("b"), 10),
136136
];
137137
for edge in expected_edges.iter() {
138-
assert_eq!(graph.edges().contains(edge), true);
138+
assert!(graph.edges().contains(edge));
139139
}
140140
}
141141

@@ -188,7 +188,7 @@ mod test_directed_graph {
188188
(&String::from("b"), &String::from("c"), 10),
189189
];
190190
for edge in expected_edges.iter() {
191-
assert_eq!(graph.edges().contains(edge), true);
191+
assert!(graph.edges().contains(edge));
192192
}
193193
}
194194

@@ -212,9 +212,9 @@ mod test_directed_graph {
212212
graph.add_node("a");
213213
graph.add_node("b");
214214
graph.add_node("c");
215-
assert_eq!(graph.contains("a"), true);
216-
assert_eq!(graph.contains("b"), true);
217-
assert_eq!(graph.contains("c"), true);
218-
assert_eq!(graph.contains("d"), false);
215+
assert!(graph.contains("a"));
216+
assert!(graph.contains("b"));
217+
assert!(graph.contains("c"));
218+
assert!(!graph.contains("d"));
219219
}
220220
}

src/data_structures/heap.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,8 @@ mod tests {
169169
assert_eq!(heap.next(), Some(2));
170170
}
171171

172+
#[derive(Default)]
172173
struct Point(/* x */ i32, /* y */ i32);
173-
impl Default for Point {
174-
fn default() -> Self {
175-
Self(0, 0)
176-
}
177-
}
178174

179175
#[test]
180176
fn test_key_heap() {

src/data_structures/linked_list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ mod tests {
481481
println!("Linked List is {}", list);
482482
let retrived_item = list.get(1);
483483
assert!(retrived_item.is_some());
484-
assert_eq!(2 as i32, *retrived_item.unwrap());
484+
assert_eq!(2, *retrived_item.unwrap());
485485
}
486486

487487
#[test]

src/data_structures/queue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ mod tests {
4747
fn test_enqueue() {
4848
let mut queue: Queue<u8> = Queue::new();
4949
queue.enqueue(64);
50-
assert_eq!(queue.is_empty(), false);
50+
assert!(!queue.is_empty());
5151
}
5252

5353
#[test]

src/data_structures/stack_using_singly_linked_list.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@ mod test_stack {
181181
list.push(4);
182182
list.push(5);
183183

184-
assert_eq!(list.is_empty(), false);
184+
assert!(!list.is_empty());
185185

186186
assert_eq!(list.pop(), Ok(5));
187187
assert_eq!(list.pop(), Ok(4));
188188

189189
assert_eq!(list.pop(), Ok(1));
190190
assert_eq!(list.pop(), Err("Stack is empty"));
191191

192-
assert_eq!(list.is_empty(), true);
192+
assert!(list.is_empty());
193193
}
194194

195195
#[test]
@@ -204,8 +204,8 @@ mod test_stack {
204204
assert_eq!(list.peek_mut(), Some(&mut 3));
205205

206206
match list.peek_mut() {
207-
None => None,
208-
Some(value) => Some(*value = 42),
207+
None => (),
208+
Some(value) => *value = 42,
209209
};
210210

211211
assert_eq!(list.peek(), Some(&42));

src/data_structures/treap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ mod tests {
337337
#[test]
338338
fn sorted() {
339339
let tree: Treap<_> = (1..8).rev().collect();
340-
assert!((1..8).eq(tree.iter().map(|&x| x)));
340+
assert!((1..8).eq(tree.iter().copied()));
341341
}
342342

343343
#[test]

src/data_structures/union_find.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ mod tests {
7474
assert_eq!(uf.find(8), 8);
7575
assert_eq!(uf.find(9), 9);
7676

77-
assert_eq!(uf.union(0, 1), true);
78-
assert_eq!(uf.union(1, 2), true);
79-
assert_eq!(uf.union(2, 3), true);
80-
assert_eq!(uf.union(3, 4), true);
81-
assert_eq!(uf.union(4, 5), true);
82-
assert_eq!(uf.union(5, 6), true);
83-
assert_eq!(uf.union(6, 7), true);
84-
assert_eq!(uf.union(7, 8), true);
85-
assert_eq!(uf.union(8, 9), true);
86-
assert_eq!(uf.union(9, 0), false);
77+
assert!(uf.union(0, 1));
78+
assert!(uf.union(1, 2));
79+
assert!(uf.union(2, 3));
80+
assert!(uf.union(3, 4));
81+
assert!(uf.union(4, 5));
82+
assert!(uf.union(5, 6));
83+
assert!(uf.union(6, 7));
84+
assert!(uf.union(7, 8));
85+
assert!(uf.union(8, 9));
86+
assert!(!uf.union(9, 0));
8787

8888
assert_eq!(1, uf.count());
8989
}

src/dynamic_programming/fractional_knapsack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ mod tests {
9191
fn test_nan() {
9292
let capacity = 36.0;
9393
// 2nd element is NaN
94-
let values = vec![25.0, 0.0 / 0.0, 25.0, 6.0, 2.0];
94+
let values = vec![25.0, f64::NAN, 25.0, 6.0, 2.0];
9595
let weights = vec![10.0, 10.0, 10.0, 4.0, 2.0];
9696
assert_eq!(fractional_knapsack(capacity, weights, values), 83.0);
9797
}

src/dynamic_programming/is_subsequence.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ mod tests {
2727

2828
#[test]
2929
fn test() {
30-
assert_eq!(
31-
is_subsequence(String::from("abc"), String::from("ahbgdc")),
32-
true
33-
);
34-
assert_eq!(
35-
is_subsequence(String::from("axc"), String::from("ahbgdc")),
36-
false
37-
);
30+
assert!(is_subsequence(String::from("abc"), String::from("ahbgdc")));
31+
assert!(!is_subsequence(String::from("axc"), String::from("ahbgdc")));
3832
}
3933
}

src/dynamic_programming/longest_increasing_subsequence.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,29 @@ mod tests {
5252
#[test]
5353
/// Need to specify generic type T in order to function
5454
fn test_empty_vec() {
55-
assert_eq!(longest_increasing_subsequence::<i32>(&vec![]), vec![]);
55+
assert_eq!(longest_increasing_subsequence::<i32>(&[]), vec![]);
5656
}
5757

5858
#[test]
5959
fn test_example_1() {
6060
assert_eq!(
61-
longest_increasing_subsequence(&vec![10, 9, 2, 5, 3, 7, 101, 18]),
61+
longest_increasing_subsequence(&[10, 9, 2, 5, 3, 7, 101, 18]),
6262
vec![2, 3, 7, 18]
6363
);
6464
}
6565

6666
#[test]
6767
fn test_example_2() {
6868
assert_eq!(
69-
longest_increasing_subsequence(&vec![0, 1, 0, 3, 2, 3]),
69+
longest_increasing_subsequence(&[0, 1, 0, 3, 2, 3]),
7070
vec![0, 1, 2, 3]
7171
);
7272
}
7373

7474
#[test]
7575
fn test_example_3() {
7676
assert_eq!(
77-
longest_increasing_subsequence(&vec![7, 7, 7, 7, 7, 7, 7]),
77+
longest_increasing_subsequence(&[7, 7, 7, 7, 7, 7, 7]),
7878
vec![7]
7979
);
8080
}
@@ -104,6 +104,6 @@ mod tests {
104104

105105
#[test]
106106
fn test_negative_elements() {
107-
assert_eq!(longest_increasing_subsequence(&vec![-2, -1]), vec![-2, -1]);
107+
assert_eq!(longest_increasing_subsequence(&[-2, -1]), vec![-2, -1]);
108108
}
109109
}

src/dynamic_programming/maximal_square.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ mod tests {
4545

4646
#[test]
4747
fn test() {
48-
assert_eq!(maximal_square(&mut vec![]), 0);
48+
assert_eq!(maximal_square(&mut []), 0);
4949

5050
let mut matrix = vec![vec![0, 1], vec![1, 0]];
5151
assert_eq!(maximal_square(&mut matrix), 1);

src/dynamic_programming/snail.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ mod test {
111111
#[test]
112112
fn test_empty() {
113113
let empty: &[Vec<i32>] = &[vec![]];
114-
assert_eq!(snail(&empty), vec![]);
114+
assert_eq!(snail(empty), vec![]);
115115
}
116116

117117
#[test]

src/general/convex_hull.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ mod tests {
7070

7171
#[test]
7272
fn empty() {
73-
assert_eq!(convex_hull_graham(&vec![]), vec![]);
73+
assert_eq!(convex_hull_graham(&[]), vec![]);
7474
}
7575

7676
#[test]

0 commit comments

Comments
 (0)