Line | Count | Source |
1 | | pub mod test; |
2 | | |
3 | 0 | fn main() { |
4 | 0 | println!("Hello, world!"); |
5 | 0 | } |
6 | | |
7 | 3 | pub fn add(a: i32, b: i32) -> i32 { |
8 | 3 | a + b |
9 | 3 | } |
10 | | |
11 | 3 | pub fn mult(a: i32, b: i32) -> i32{ |
12 | 3 | a * b |
13 | 3 | } |
14 | | |
15 | | #[cfg(test)] |
16 | | mod tests { |
17 | | use crate::test::test; |
18 | | |
19 | | use super::*; // This allows access to the functions in the parent module |
20 | | |
21 | | #[test] |
22 | 1 | fn test_add() { |
23 | 1 | // Test the add function |
24 | 1 | assert_eq!(add(2, 3), 5); // Expecting 2 + 3 = 5 |
25 | 1 | assert_eq!(add(-1, 1), 0); // Expecting -1 + 1 = 0 |
26 | 1 | assert_eq!(add(0, 0), 0); // Expecting 0 + 0 = 0 |
27 | 1 | } |
28 | | |
29 | | #[test] |
30 | 1 | fn test_mult(){ |
31 | 1 | assert_eq!(mult(2,2), 4); |
32 | 1 | assert_eq!(mult(0, 5), 0); |
33 | 1 | assert_eq!(mult(7,7), 49); |
34 | 1 | } |
35 | | |
36 | | #[test] |
37 | 1 | fn test_test(){ |
38 | 1 | test(); |
39 | 1 | } |
40 | | } |