Skip to content

Updated rand, tidy up, apply clippy fixes #11

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

Merged
merged 1 commit into from
Jan 28, 2025
Merged
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
20 changes: 10 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: 2
updates:
- package-ecosystem: cargo
directory: "/"
schedule:
interval: daily
time: "10:00"
open-pull-requests-limit: 10
reviewers:
- brndnmtthws
assignees:
- brndnmtthws
- package-ecosystem: cargo
directory: "/"
schedule:
interval: weekly
time: "10:00"
open-pull-requests-limit: 10
reviewers:
- brndnmtthws
assignees:
- brndnmtthws
7 changes: 4 additions & 3 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ jobs:
- uses: actions/checkout@v3
- name: Setup Rust toolchain with caching
uses: brndnmtthws/rust-action@v1
with:
cargo-packages: cargo-nextest
- run: cargo build
- run: cargo test
env:
RUST_BACKTRACE: 1
- run: cargo clippy
- run: cargo nextest run
12 changes: 12 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
enum_discrim_align_threshold = 60
format_code_in_doc_comments = true
format_macro_matchers = true
format_strings = true
group_imports = "StdExternalCrate"
imports_granularity = "Module"
# normalize_comments = true
reorder_impl_items = true
unstable_features = true
use_field_init_shorthand = true
style_edition = "2024"
wrap_comments = true
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "cracking-the-coding-interview"
version = "0.1.0"
authors = ["Brenden Matthews <brenden@diddyinc.com>"]
authors = ["Brenden Matthews <brenden@brndn.io>"]
edition = "2018"

[dependencies]
rand = "0.8"
rand = "0.9"
num = "0.4"
17 changes: 8 additions & 9 deletions src/bin/c01p01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,23 @@ fn all_chars_unique_part_b(s: &str) -> bool {
true
}

fn main() {
all_chars_unique_part_a(&String::from("helloworld"));
all_chars_unique_part_b(&String::from("helloworld"));
}
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_part_a() {
assert_eq!(all_chars_unique_part_a(&String::from("abcdefg")), true);
assert_eq!(all_chars_unique_part_a(&String::from("abcdefga")), false);
assert!(all_chars_unique_part_a(&String::from("abcdefg")));
assert!(!all_chars_unique_part_a(&String::from("abcdefga")));
}

#[test]
fn test_part_b() {
assert_eq!(all_chars_unique_part_b(&String::from("abcdefg")), true);
assert_eq!(all_chars_unique_part_b(&String::from("abcdefga")), false);
assert!(all_chars_unique_part_b(&String::from("abcdefg")));
assert!(!all_chars_unique_part_b(&String::from("abcdefga")));
}
}

fn main() {
all_chars_unique_part_a(&String::from("helloworld"));
all_chars_unique_part_b(&String::from("helloworld"));
}
18 changes: 6 additions & 12 deletions src/bin/c01p02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,17 @@ fn is_permutation(s1: &str, s2: &str) -> bool {
true
}

fn main() {
is_permutation(&String::from("cat"), &String::from("dog"));
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_is_permutation() {
assert_eq!(
is_permutation(&String::from("cat"), &String::from("tac")),
true
);
assert_eq!(
is_permutation(&String::from("cat"), &String::from("dog")),
false
);
assert!(is_permutation(&String::from("cat"), &String::from("tac")));
assert!(!is_permutation(&String::from("cat"), &String::from("dog")));
}
}

fn main() {
is_permutation(&String::from("cat"), &String::from("dog"));
}
10 changes: 5 additions & 5 deletions src/bin/c01p03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ fn urlify_2(url: &str) -> String {
url.trim().replace(' ', "%20")
}

fn main() {
urlify("Mr John Smith ");
urlify_2("Mr John Smith ");
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -28,8 +33,3 @@ mod tests {
assert_eq!(urlify_2("Mr John Smith "), "Mr%20John%20Smith");
}
}

fn main() {
urlify("Mr John Smith ");
urlify_2("Mr John Smith ");
}
12 changes: 6 additions & 6 deletions src/bin/c01p04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn count_chars(s: &str) -> HashMap<char, i32> {
characters
}

fn palidrome_permutations(s: &str) -> bool {
fn palindrome_permutations(s: &str) -> bool {
let normalized_s = s
.to_lowercase()
.split_whitespace()
Expand All @@ -33,16 +33,16 @@ fn palidrome_permutations(s: &str) -> bool {
true
}

fn main() {
palindrome_permutations("Tact Coa");
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_palindrome_permutation() {
assert_eq!(palidrome_permutations("Tact Coa"), true);
assert!(palindrome_permutations("Tact Coa"));
}
}

fn main() {
palidrome_permutations("Tact Coa");
}
24 changes: 12 additions & 12 deletions src/bin/c01p05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ fn is_one_edit_away(s1: &str, s2: &str) -> bool {
one_char_inserted(s1, s2)
}

fn main() {
is_one_edit_away("pale", "ple");
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_is_one_edit_away() {
assert_eq!(is_one_edit_away("pale", "pale"), true);
assert_eq!(is_one_edit_away("pale", "ple"), true);
assert_eq!(is_one_edit_away("pales", "pale"), true);
assert_eq!(is_one_edit_away("pale", "bale"), true);
assert_eq!(is_one_edit_away("pale", "bake"), false);
assert!(is_one_edit_away("pale", "pale"));
assert!(is_one_edit_away("pale", "ple"));
assert!(is_one_edit_away("pales", "pale"));
assert!(is_one_edit_away("pale", "bale"));
assert!(!is_one_edit_away("pale", "bake"));

assert_eq!(is_one_edit_away("pale", "8e9auh"), false);
assert_eq!(is_one_edit_away("pale", ""), false);
assert_eq!(is_one_edit_away("pale", "pale "), true);
assert!(!is_one_edit_away("pale", "8e9auh"));
assert!(!is_one_edit_away("pale", ""));
assert!(is_one_edit_away("pale", "pale "));
}
}

fn main() {
is_one_edit_away("pale", "ple");
}
8 changes: 4 additions & 4 deletions src/bin/c01p06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ fn compress_string(s: &str) -> String {
result
}

fn main() {
compress_string("aabcccccaaa");
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -35,7 +39,3 @@ mod tests {
);
}
}

fn main() {
compress_string("aabcccccaaa");
}
8 changes: 4 additions & 4 deletions src/bin/c01p07.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ fn rotate_image_90_degrees(image: &[Vec<u32>]) -> Image {
rotated_image
}

fn main() {
rotate_image_90_degrees(&[vec![1]]);
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -52,7 +56,3 @@ mod tests {
assert_eq!(rotated_image, expected_rotated_image);
}
}

fn main() {
rotate_image_90_degrees(&[vec![1]]);
}
56 changes: 24 additions & 32 deletions src/bin/c01p08.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,39 @@ fn zero_matrix_where_zero(mat: &[Vec<u32>]) -> Mat {
result
}

fn main() {
zero_matrix_where_zero(&[vec![0]]);
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_zero_matrix_where_zeros() {
assert_eq!(zero_matrix_where_zero(&[vec![0, 1], vec![1, 1]]), [
vec![0, 0],
vec![0, 1]
]);
assert_eq!(
zero_matrix_where_zero(&[vec![0, 1], vec![1, 1]]),
[vec![0, 0], vec![0, 1]]
);
assert_eq!(
zero_matrix_where_zero(&[
vec![0, 1, 1, 1],
vec![1, 1, 1, 1],
vec![1, 1, 1, 1],
vec![1, 1, 1, 1],
]),
[
vec![0, 0, 0, 0],
vec![0, 1, 1, 1],
vec![0, 1, 1, 1],
vec![0, 1, 1, 1],
]
zero_matrix_where_zero(
&[vec![0, 1, 1, 1], vec![1, 1, 1, 1], vec![1, 1, 1, 1], vec![
1, 1, 1, 1
],]
),
[vec![0, 0, 0, 0], vec![0, 1, 1, 1], vec![0, 1, 1, 1], vec![
0, 1, 1, 1
],]
);
assert_eq!(
zero_matrix_where_zero(&[
vec![1, 1, 1, 1],
vec![1, 1, 1, 1],
vec![1, 1, 0, 1],
vec![1, 1, 1, 1],
]),
[
vec![1, 1, 0, 1],
vec![1, 1, 0, 1],
vec![0, 0, 0, 0],
vec![1, 1, 0, 1],
]
zero_matrix_where_zero(
&[vec![1, 1, 1, 1], vec![1, 1, 1, 1], vec![1, 1, 0, 1], vec![
1, 1, 1, 1
],]
),
[vec![1, 1, 0, 1], vec![1, 1, 0, 1], vec![0, 0, 0, 0], vec![
1, 1, 0, 1
],]
);
}
}

fn main() {
zero_matrix_where_zero(&[vec![0]]);
}
12 changes: 6 additions & 6 deletions src/bin/c01p09.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ fn is_rotated_string(s1: &str, s2: &str) -> bool {
triplet.contains(s2)
}

fn main() {
is_rotated_string("waterbottle", "erbottlewat");
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_string_rotation() {
assert_eq!(is_rotated_string("waterbottle", "erbottlewat"), true);
assert_eq!(is_rotated_string("herpderp", "lolbob"), false);
assert!(is_rotated_string("waterbottle", "erbottlewat"));
assert!(!is_rotated_string("herpderp", "lolbob"));
}
}

fn main() {
is_rotated_string("waterbottle", "erbottlewat");
}
Loading