Skip to content

Commit 57bdd49

Browse files
committed
testing
1 parent 58dce08 commit 57bdd49

File tree

8 files changed

+44
-61
lines changed

8 files changed

+44
-61
lines changed

adder/Cargo.lock

Lines changed: 0 additions & 7 deletions
This file was deleted.

adder/Cargo.toml

Lines changed: 0 additions & 6 deletions
This file was deleted.

adder/src/lib.rs

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod myutils;

src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
mod guessgame;
22
mod basics;
3-
mod myutils {
4-
pub mod stuff;
5-
}
6-
use myutils::stuff;
3+
use rustcourse::myutils::stuff;
4+
use rustcourse::myutils::testing;
75

86
fn main() {
97
basics::basics();
108
println!();
119
stuff::collections();
1210
stuff::lifetimes();
11+
testing::add(2, 2);
1312
println!();
1413
stuff::error_handling();
1514
guessgame::guess_game();

src/myutils/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod stuff;
2+
pub mod testing;

src/myutils/testing.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
pub fn add(a: i32, b: i32) -> i32 {
2+
internal_add(a, b)
3+
}
4+
5+
fn internal_add(a: i32, b: i32) -> i32 {
6+
a + b
7+
}
8+
9+
#[cfg(test)]
10+
mod tests {
11+
use super::*;
12+
13+
#[test]
14+
fn it_works() -> Result<(), String> {
15+
if internal_add(2, 2) == 4 {
16+
Ok(())
17+
} else {
18+
Err(String::from("two plus two does not equal four"))
19+
}
20+
}
21+
22+
#[test]
23+
fn it_works2() {
24+
assert_eq!(internal_add(2, 2), 4);
25+
}
26+
}

tests/integration_tests.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use rustcourse::myutils;
2+
3+
#[cfg(test)]
4+
mod tests {
5+
use super::myutils::testing;
6+
7+
#[test]
8+
fn test_add() {
9+
let result = testing::add(3, 5);
10+
assert_eq!(result, 8);
11+
}
12+
}

0 commit comments

Comments
 (0)