Skip to content

Commit

Permalink
adding immutable testing
Browse files Browse the repository at this point in the history
  • Loading branch information
noahgift committed Sep 7, 2023
1 parent 7570470 commit 403ee7b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions immutable-testing/Cargo.toml
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]
13 changes: 13 additions & 0 deletions immutable-testing/Makefile
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
25 changes: 25 additions & 0 deletions immutable-testing/src/lib.rs
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);
}
}
9 changes: 9 additions & 0 deletions immutable-testing/src/main.rs
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());
}

0 comments on commit 403ee7b

Please sign in to comment.