Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ddaletski committed May 9, 2023
1 parent e7959dc commit 6947f34
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 21 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/cargo-test.yml
Original file line number Diff line number Diff line change
@@ -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

17 changes: 2 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 16 additions & 1 deletion rust/README.md
Original file line number Diff line number Diff line change
@@ -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`
6 changes: 3 additions & 3 deletions rust/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion rust/problems/design-bitset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Bitset {

#[cfg(test)]
mod test {
use common::assert_returns;


use crate::Bitset;

Expand Down
2 changes: 1 addition & 1 deletion rust/problems/three-sum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl Solution {

#[cfg(test)]
mod tests {
use common::{assert_returns, vec2d};
use common::{vec2d};

use super::*;

Expand Down

0 comments on commit 6947f34

Please sign in to comment.