generated from noahgift/rust-new-project-template
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "immutable-testing" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
format: | ||
cargo fmt --quiet | ||
|
||
lint: | ||
cargo clippy --quiet | ||
|
||
test: | ||
cargo test --quiet | ||
|
||
run: | ||
cargo run | ||
|
||
all: format lint test run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* Calculator that uses an immutable vector | ||
Lets make our vector a constant so that we can use it in our tests | ||
*/ | ||
|
||
// a vector of immutable integers | ||
const V: [i32; 3] = [1, 2, 3]; | ||
|
||
// add all the elements in the vector | ||
pub fn add() -> i32 { | ||
let mut sum = 0; | ||
for i in &V { | ||
sum += i; | ||
} | ||
sum | ||
} | ||
|
||
/*These are the tests */ | ||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
#[test] | ||
fn test_add() { | ||
assert_eq!(add(), 6); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
Uses lib.rs to add all the elements in the vector | ||
*/ | ||
use immutable_testing::add; | ||
|
||
fn main() { | ||
//print the result | ||
println!("The sum of the elements in the vector is: {}", add()); | ||
} |