diff --git a/.github/workflows/cargo-test.yml b/.github/workflows/cargo-test.yml new file mode 100644 index 0000000..91b9a73 --- /dev/null +++ b/.github/workflows/cargo-test.yml @@ -0,0 +1,28 @@ +name: Rust + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: rust + + steps: + - uses: actions/checkout@v3 + - name: Install deps + run: sudo apt update && sudo apt install -y cargo + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose + diff --git a/README.md b/README.md index 8089841..b3587d1 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,5 @@ # Leetcode -My leetcode solutions in Rust +My leetcode solutions - -## Usage - -Every directory under `problems/` is a cargo project which contains some basic test cases. - -The whole project is a cargo workspace, -so all solutions can be tested using `cargo test` from repository root - - -## Common - -The workspace contains a `common` crate which is used in tests -and also contains leetcode-compatible definitions of common data structures, -like `TreeNode` and `ListNode` +![Visualization of this repo](./diagram.svg) diff --git a/rust/README.md b/rust/README.md index d7c84d1..8089841 100644 --- a/rust/README.md +++ b/rust/README.md @@ -1,3 +1,18 @@ # Leetcode -My leetcode solutions +My leetcode solutions in Rust + + +## Usage + +Every directory under `problems/` is a cargo project which contains some basic test cases. + +The whole project is a cargo workspace, +so all solutions can be tested using `cargo test` from repository root + + +## Common + +The workspace contains a `common` crate which is used in tests +and also contains leetcode-compatible definitions of common data structures, +like `TreeNode` and `ListNode` diff --git a/rust/common/src/lib.rs b/rust/common/src/lib.rs index 450e7cc..5b85170 100644 --- a/rust/common/src/lib.rs +++ b/rust/common/src/lib.rs @@ -9,17 +9,17 @@ macro_rules! assert_returns { // it as a string along with its result. // The `expr` designator is used for expressions. ($ret_value:expr, $func:expr, $($args:expr),*) => { - let result = $func($($args),*); - let mut args_str: String = "".into(); $( args_str += format!("{:?}, ", $args).as_str(); )* args_str.pop(); args_str.pop(); + + let result = $func($($args),*); // `stringify!` will convert the expression *as it is* into a string. - let mut error_msg = format!( + let error_msg = format!( "{}({}) returned {:?}\nexpected result: {:?}\n", stringify!($func), args_str, diff --git a/rust/problems/design-bitset/src/lib.rs b/rust/problems/design-bitset/src/lib.rs index b5d326d..e559502 100644 --- a/rust/problems/design-bitset/src/lib.rs +++ b/rust/problems/design-bitset/src/lib.rs @@ -93,7 +93,7 @@ impl Bitset { #[cfg(test)] mod test { - use common::assert_returns; + use crate::Bitset; diff --git a/rust/problems/three-sum/src/lib.rs b/rust/problems/three-sum/src/lib.rs index 334e15a..79f9fef 100644 --- a/rust/problems/three-sum/src/lib.rs +++ b/rust/problems/three-sum/src/lib.rs @@ -250,7 +250,7 @@ impl Solution { #[cfg(test)] mod tests { - use common::{assert_returns, vec2d}; + use common::{vec2d}; use super::*;