Skip to content

Commit ad7ec45

Browse files
authored
Fix Clippy warings (TheAlgorithms#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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 11 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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
}

0 commit comments

Comments
 (0)