Skip to content

Commit 25bb6b9

Browse files
committed
Updated rand, tidy up, apply clippy fixes
1 parent 80d973f commit 25bb6b9

Some content is hidden

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

72 files changed

+796
-812
lines changed

.github/dependabot.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
version: 2
22
updates:
3-
- package-ecosystem: cargo
4-
directory: "/"
5-
schedule:
6-
interval: daily
7-
time: "10:00"
8-
open-pull-requests-limit: 10
9-
reviewers:
10-
- brndnmtthws
11-
assignees:
12-
- brndnmtthws
3+
- package-ecosystem: cargo
4+
directory: "/"
5+
schedule:
6+
interval: weekly
7+
time: "10:00"
8+
open-pull-requests-limit: 10
9+
reviewers:
10+
- brndnmtthws
11+
assignees:
12+
- brndnmtthws

.github/workflows/build-and-test.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ jobs:
1111
- uses: actions/checkout@v3
1212
- name: Setup Rust toolchain with caching
1313
uses: brndnmtthws/rust-action@v1
14+
with:
15+
cargo-packages: cargo-nextest
1416
- run: cargo build
15-
- run: cargo test
16-
env:
17-
RUST_BACKTRACE: 1
17+
- run: cargo clippy
18+
- run: cargo nextest run

.rustfmt.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
enum_discrim_align_threshold = 60
2+
format_code_in_doc_comments = true
3+
format_macro_matchers = true
4+
format_strings = true
5+
group_imports = "StdExternalCrate"
6+
imports_granularity = "Module"
7+
# normalize_comments = true
8+
reorder_impl_items = true
9+
unstable_features = true
10+
use_field_init_shorthand = true
11+
style_edition = "2024"
12+
wrap_comments = true

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
22
name = "cracking-the-coding-interview"
33
version = "0.1.0"
4-
authors = ["Brenden Matthews <brenden@diddyinc.com>"]
4+
authors = ["Brenden Matthews <brenden@brndn.io>"]
55
edition = "2018"
66

77
[dependencies]
8-
rand = "0.8"
8+
rand = "0.9"
99
num = "0.4"

src/bin/c01p01.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,23 @@ fn all_chars_unique_part_b(s: &str) -> bool {
3030
true
3131
}
3232

33+
fn main() {
34+
all_chars_unique_part_a(&String::from("helloworld"));
35+
all_chars_unique_part_b(&String::from("helloworld"));
36+
}
3337
#[cfg(test)]
3438
mod tests {
3539
use super::*;
3640

3741
#[test]
3842
fn test_part_a() {
39-
assert_eq!(all_chars_unique_part_a(&String::from("abcdefg")), true);
40-
assert_eq!(all_chars_unique_part_a(&String::from("abcdefga")), false);
43+
assert!(all_chars_unique_part_a(&String::from("abcdefg")));
44+
assert!(!all_chars_unique_part_a(&String::from("abcdefga")));
4145
}
4246

4347
#[test]
4448
fn test_part_b() {
45-
assert_eq!(all_chars_unique_part_b(&String::from("abcdefg")), true);
46-
assert_eq!(all_chars_unique_part_b(&String::from("abcdefga")), false);
49+
assert!(all_chars_unique_part_b(&String::from("abcdefg")));
50+
assert!(!all_chars_unique_part_b(&String::from("abcdefga")));
4751
}
4852
}
49-
50-
fn main() {
51-
all_chars_unique_part_a(&String::from("helloworld"));
52-
all_chars_unique_part_b(&String::from("helloworld"));
53-
}

src/bin/c01p02.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,17 @@ fn is_permutation(s1: &str, s2: &str) -> bool {
2828
true
2929
}
3030

31+
fn main() {
32+
is_permutation(&String::from("cat"), &String::from("dog"));
33+
}
34+
3135
#[cfg(test)]
3236
mod tests {
3337
use super::*;
3438

3539
#[test]
3640
fn test_is_permutation() {
37-
assert_eq!(
38-
is_permutation(&String::from("cat"), &String::from("tac")),
39-
true
40-
);
41-
assert_eq!(
42-
is_permutation(&String::from("cat"), &String::from("dog")),
43-
false
44-
);
41+
assert!(is_permutation(&String::from("cat"), &String::from("tac")));
42+
assert!(!is_permutation(&String::from("cat"), &String::from("dog")));
4543
}
4644
}
47-
48-
fn main() {
49-
is_permutation(&String::from("cat"), &String::from("dog"));
50-
}

src/bin/c01p03.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ fn urlify_2(url: &str) -> String {
1515
url.trim().replace(' ', "%20")
1616
}
1717

18+
fn main() {
19+
urlify("Mr John Smith ");
20+
urlify_2("Mr John Smith ");
21+
}
22+
1823
#[cfg(test)]
1924
mod tests {
2025
use super::*;
@@ -28,8 +33,3 @@ mod tests {
2833
assert_eq!(urlify_2("Mr John Smith "), "Mr%20John%20Smith");
2934
}
3035
}
31-
32-
fn main() {
33-
urlify("Mr John Smith ");
34-
urlify_2("Mr John Smith ");
35-
}

src/bin/c01p04.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn count_chars(s: &str) -> HashMap<char, i32> {
88
characters
99
}
1010

11-
fn palidrome_permutations(s: &str) -> bool {
11+
fn palindrome_permutations(s: &str) -> bool {
1212
let normalized_s = s
1313
.to_lowercase()
1414
.split_whitespace()
@@ -33,16 +33,16 @@ fn palidrome_permutations(s: &str) -> bool {
3333
true
3434
}
3535

36+
fn main() {
37+
palindrome_permutations("Tact Coa");
38+
}
39+
3640
#[cfg(test)]
3741
mod tests {
3842
use super::*;
3943

4044
#[test]
4145
fn test_palindrome_permutation() {
42-
assert_eq!(palidrome_permutations("Tact Coa"), true);
46+
assert!(palindrome_permutations("Tact Coa"));
4347
}
4448
}
45-
46-
fn main() {
47-
palidrome_permutations("Tact Coa");
48-
}

src/bin/c01p05.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,24 @@ fn is_one_edit_away(s1: &str, s2: &str) -> bool {
4141
one_char_inserted(s1, s2)
4242
}
4343

44+
fn main() {
45+
is_one_edit_away("pale", "ple");
46+
}
47+
4448
#[cfg(test)]
4549
mod tests {
4650
use super::*;
4751

4852
#[test]
4953
fn test_is_one_edit_away() {
50-
assert_eq!(is_one_edit_away("pale", "pale"), true);
51-
assert_eq!(is_one_edit_away("pale", "ple"), true);
52-
assert_eq!(is_one_edit_away("pales", "pale"), true);
53-
assert_eq!(is_one_edit_away("pale", "bale"), true);
54-
assert_eq!(is_one_edit_away("pale", "bake"), false);
54+
assert!(is_one_edit_away("pale", "pale"));
55+
assert!(is_one_edit_away("pale", "ple"));
56+
assert!(is_one_edit_away("pales", "pale"));
57+
assert!(is_one_edit_away("pale", "bale"));
58+
assert!(!is_one_edit_away("pale", "bake"));
5559

56-
assert_eq!(is_one_edit_away("pale", "8e9auh"), false);
57-
assert_eq!(is_one_edit_away("pale", ""), false);
58-
assert_eq!(is_one_edit_away("pale", "pale "), true);
60+
assert!(!is_one_edit_away("pale", "8e9auh"));
61+
assert!(!is_one_edit_away("pale", ""));
62+
assert!(is_one_edit_away("pale", "pale "));
5963
}
6064
}
61-
62-
fn main() {
63-
is_one_edit_away("pale", "ple");
64-
}

src/bin/c01p06.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ fn compress_string(s: &str) -> String {
2222
result
2323
}
2424

25+
fn main() {
26+
compress_string("aabcccccaaa");
27+
}
28+
2529
#[cfg(test)]
2630
mod tests {
2731
use super::*;
@@ -35,7 +39,3 @@ mod tests {
3539
);
3640
}
3741
}
38-
39-
fn main() {
40-
compress_string("aabcccccaaa");
41-
}

src/bin/c01p07.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ fn rotate_image_90_degrees(image: &[Vec<u32>]) -> Image {
2828
rotated_image
2929
}
3030

31+
fn main() {
32+
rotate_image_90_degrees(&[vec![1]]);
33+
}
34+
3135
#[cfg(test)]
3236
mod tests {
3337
use super::*;
@@ -52,7 +56,3 @@ mod tests {
5256
assert_eq!(rotated_image, expected_rotated_image);
5357
}
5458
}
55-
56-
fn main() {
57-
rotate_image_90_degrees(&[vec![1]]);
58-
}

src/bin/c01p08.rs

+24-32
Original file line numberDiff line numberDiff line change
@@ -26,47 +26,39 @@ fn zero_matrix_where_zero(mat: &[Vec<u32>]) -> Mat {
2626
result
2727
}
2828

29+
fn main() {
30+
zero_matrix_where_zero(&[vec![0]]);
31+
}
32+
2933
#[cfg(test)]
3034
mod tests {
3135
use super::*;
3236

3337
#[test]
3438
fn test_zero_matrix_where_zeros() {
39+
assert_eq!(zero_matrix_where_zero(&[vec![0, 1], vec![1, 1]]), [
40+
vec![0, 0],
41+
vec![0, 1]
42+
]);
3543
assert_eq!(
36-
zero_matrix_where_zero(&[vec![0, 1], vec![1, 1]]),
37-
[vec![0, 0], vec![0, 1]]
38-
);
39-
assert_eq!(
40-
zero_matrix_where_zero(&[
41-
vec![0, 1, 1, 1],
42-
vec![1, 1, 1, 1],
43-
vec![1, 1, 1, 1],
44-
vec![1, 1, 1, 1],
45-
]),
46-
[
47-
vec![0, 0, 0, 0],
48-
vec![0, 1, 1, 1],
49-
vec![0, 1, 1, 1],
50-
vec![0, 1, 1, 1],
51-
]
44+
zero_matrix_where_zero(
45+
&[vec![0, 1, 1, 1], vec![1, 1, 1, 1], vec![1, 1, 1, 1], vec![
46+
1, 1, 1, 1
47+
],]
48+
),
49+
[vec![0, 0, 0, 0], vec![0, 1, 1, 1], vec![0, 1, 1, 1], vec![
50+
0, 1, 1, 1
51+
],]
5252
);
5353
assert_eq!(
54-
zero_matrix_where_zero(&[
55-
vec![1, 1, 1, 1],
56-
vec![1, 1, 1, 1],
57-
vec![1, 1, 0, 1],
58-
vec![1, 1, 1, 1],
59-
]),
60-
[
61-
vec![1, 1, 0, 1],
62-
vec![1, 1, 0, 1],
63-
vec![0, 0, 0, 0],
64-
vec![1, 1, 0, 1],
65-
]
54+
zero_matrix_where_zero(
55+
&[vec![1, 1, 1, 1], vec![1, 1, 1, 1], vec![1, 1, 0, 1], vec![
56+
1, 1, 1, 1
57+
],]
58+
),
59+
[vec![1, 1, 0, 1], vec![1, 1, 0, 1], vec![0, 0, 0, 0], vec![
60+
1, 1, 0, 1
61+
],]
6662
);
6763
}
6864
}
69-
70-
fn main() {
71-
zero_matrix_where_zero(&[vec![0]]);
72-
}

src/bin/c01p09.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ fn is_rotated_string(s1: &str, s2: &str) -> bool {
44
triplet.contains(s2)
55
}
66

7+
fn main() {
8+
is_rotated_string("waterbottle", "erbottlewat");
9+
}
10+
711
#[cfg(test)]
812
mod tests {
913
use super::*;
1014

1115
#[test]
1216
fn test_string_rotation() {
13-
assert_eq!(is_rotated_string("waterbottle", "erbottlewat"), true);
14-
assert_eq!(is_rotated_string("herpderp", "lolbob"), false);
17+
assert!(is_rotated_string("waterbottle", "erbottlewat"));
18+
assert!(!is_rotated_string("herpderp", "lolbob"));
1519
}
1620
}
17-
18-
fn main() {
19-
is_rotated_string("waterbottle", "erbottlewat");
20-
}

0 commit comments

Comments
 (0)