Skip to content

Commit f4a5749

Browse files
authored
Merge pull request #1 from AndresCdo/dev
Remove unnecessary Cargo.lock and .fingerprint files
2 parents 81ca55d + db5e42f commit f4a5749

File tree

1,120 files changed

+564
-33405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,120 files changed

+564
-33405
lines changed

Module00/Cargo.lock

-7
This file was deleted.

Module01/SimpleCalc/Cargo.lock

-7
This file was deleted.

Module01/SimpleCalc/src/main.rs

+137-133
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,137 @@
1-
use std::io;
2-
3-
/// Reads a number from the user's input.
4-
///
5-
/// # Returns
6-
///
7-
/// A `f64` representing the number entered by the user.
8-
///
9-
/// # Panics
10-
///
11-
/// Panics if the user input is not a valid number.
12-
fn read_number() -> f64 {
13-
let mut input = String::new();
14-
io::stdin().read_line(&mut input).expect("Failed to read line");
15-
input.trim().parse().expect("Please type a number!")
16-
}
17-
18-
/// Performs a calculation based on the given operator and numbers.
19-
///
20-
/// # Arguments
21-
///
22-
/// * `operator` - The operator to use for the calculation.
23-
/// * `num1` - The first number.
24-
/// * `num2` - The second number.
25-
///
26-
/// # Returns
27-
///
28-
/// A `String` containing the result of the calculation or an error message.
29-
fn calculate(operator: &str, num1: f64, num2: f64) -> String {
30-
match operator {
31-
"+" => format!("Result: {}", num1 + num2),
32-
"-" => format!("Result: {}", num1 - num2),
33-
"*" => format!("Result: {}", num1 * num2),
34-
"/" => {
35-
if num2 != 0.0 {
36-
format!("Result: {}", num1 / num2)
37-
} else {
38-
"Cannot divide by zero".to_string()
39-
}
40-
},
41-
_ => "Invalid operation".to_string(),
42-
}
43-
}
44-
45-
fn main() {
46-
println!("Welcome to crazy cure\n");
47-
48-
println!("Enter the first number :");
49-
let num1 = read_number();
50-
51-
println!("Enter the second number :");
52-
let num2 = read_number();
53-
54-
println!("Choose an operation: +, -, *, /");
55-
let mut operator = String::new();
56-
io::stdin().read_line(&mut operator).expect("Failed to read line");
57-
58-
let result = calculate(operator.trim(), num1, num2);
59-
println!("{}", result);
60-
}
61-
62-
#[cfg(test)]
63-
mod tests {
64-
use super::*;
65-
66-
// #[test]
67-
// fn test_read_number() {
68-
// let _input = "42\n";
69-
// let expected = 42.0;
70-
// let result = read_number();
71-
// assert_eq!(result, expected);
72-
// }
73-
74-
#[test]
75-
fn test_calculate_addition() {
76-
let operator = "+";
77-
let num1 = 10.0;
78-
let num2 = 5.0;
79-
let expected = "Result: 15".to_string();
80-
let result = calculate(operator, num1, num2);
81-
assert_eq!(result, expected);
82-
}
83-
84-
#[test]
85-
fn test_calculate_subtraction() {
86-
let operator = "-";
87-
let num1 = 10.0;
88-
let num2 = 5.0;
89-
let expected = "Result: 5".to_string();
90-
let result = calculate(operator, num1, num2);
91-
assert_eq!(result, expected);
92-
}
93-
94-
#[test]
95-
fn test_calculate_multiplication() {
96-
let operator = "*";
97-
let num1 = 10.0;
98-
let num2 = 5.0;
99-
let expected = "Result: 50".to_string();
100-
let result = calculate(operator, num1, num2);
101-
assert_eq!(result, expected);
102-
}
103-
104-
#[test]
105-
fn test_calculate_division() {
106-
let operator = "/";
107-
let num1 = 10.0;
108-
let num2 = 5.0;
109-
let expected = "Result: 2".to_string();
110-
let result = calculate(operator, num1, num2);
111-
assert_eq!(result, expected);
112-
}
113-
114-
#[test]
115-
fn test_calculate_division_by_zero() {
116-
let operator = "/";
117-
let num1 = 10.0;
118-
let num2 = 0.0;
119-
let expected = "Cannot divide by zero".to_string();
120-
let result = calculate(operator, num1, num2);
121-
assert_eq!(result, expected);
122-
}
123-
124-
#[test]
125-
fn test_calculate_invalid_operation() {
126-
let operator = "%";
127-
let num1 = 10.0;
128-
let num2 = 5.0;
129-
let expected = "Invalid operation".to_string();
130-
let result = calculate(operator, num1, num2);
131-
assert_eq!(result, expected);
132-
}
133-
}
1+
use std::io;
2+
3+
/// Reads a number from the user's input.
4+
///
5+
/// # Returns
6+
///
7+
/// A `f64` representing the number entered by the user.
8+
///
9+
/// # Panics
10+
///
11+
/// Panics if the user input is not a valid number.
12+
fn read_number() -> f64 {
13+
let mut input = String::new();
14+
io::stdin()
15+
.read_line(&mut input)
16+
.expect("Failed to read line");
17+
input.trim().parse().expect("Please type a number!")
18+
}
19+
20+
/// Performs a calculation based on the given operator and numbers.
21+
///
22+
/// # Arguments
23+
///
24+
/// * `operator` - The operator to use for the calculation.
25+
/// * `num1` - The first number.
26+
/// * `num2` - The second number.
27+
///
28+
/// # Returns
29+
///
30+
/// A `String` containing the result of the calculation or an error message.
31+
fn calculate(operator: &str, num1: f64, num2: f64) -> String {
32+
match operator {
33+
"+" => format!("Result: {}", num1 + num2),
34+
"-" => format!("Result: {}", num1 - num2),
35+
"*" => format!("Result: {}", num1 * num2),
36+
"/" => {
37+
if num2 != 0.0 {
38+
format!("Result: {}", num1 / num2)
39+
} else {
40+
"Cannot divide by zero".to_string()
41+
}
42+
}
43+
_ => "Invalid operation".to_string(),
44+
}
45+
}
46+
47+
fn main() {
48+
println!("Welcome to crazy cure\n");
49+
50+
println!("Enter the first number :");
51+
let num1 = read_number();
52+
53+
println!("Enter the second number :");
54+
let num2 = read_number();
55+
56+
println!("Choose an operation: +, -, *, /");
57+
let mut operator = String::new();
58+
io::stdin()
59+
.read_line(&mut operator)
60+
.expect("Failed to read line");
61+
62+
let result = calculate(operator.trim(), num1, num2);
63+
println!("{}", result);
64+
}
65+
66+
#[cfg(test)]
67+
mod tests {
68+
use super::*;
69+
70+
// #[test]
71+
// fn test_read_number() {
72+
// let _input = "42\n";
73+
// let expected = 42.0;
74+
// let result = read_number();
75+
// assert_eq!(result, expected);
76+
// }
77+
78+
#[test]
79+
fn test_calculate_addition() {
80+
let operator = "+";
81+
let num1 = 10.0;
82+
let num2 = 5.0;
83+
let expected = "Result: 15".to_string();
84+
let result = calculate(operator, num1, num2);
85+
assert_eq!(result, expected);
86+
}
87+
88+
#[test]
89+
fn test_calculate_subtraction() {
90+
let operator = "-";
91+
let num1 = 10.0;
92+
let num2 = 5.0;
93+
let expected = "Result: 5".to_string();
94+
let result = calculate(operator, num1, num2);
95+
assert_eq!(result, expected);
96+
}
97+
98+
#[test]
99+
fn test_calculate_multiplication() {
100+
let operator = "*";
101+
let num1 = 10.0;
102+
let num2 = 5.0;
103+
let expected = "Result: 50".to_string();
104+
let result = calculate(operator, num1, num2);
105+
assert_eq!(result, expected);
106+
}
107+
108+
#[test]
109+
fn test_calculate_division() {
110+
let operator = "/";
111+
let num1 = 10.0;
112+
let num2 = 5.0;
113+
let expected = "Result: 2".to_string();
114+
let result = calculate(operator, num1, num2);
115+
assert_eq!(result, expected);
116+
}
117+
118+
#[test]
119+
fn test_calculate_division_by_zero() {
120+
let operator = "/";
121+
let num1 = 10.0;
122+
let num2 = 0.0;
123+
let expected = "Cannot divide by zero".to_string();
124+
let result = calculate(operator, num1, num2);
125+
assert_eq!(result, expected);
126+
}
127+
128+
#[test]
129+
fn test_calculate_invalid_operation() {
130+
let operator = "%";
131+
let num1 = 10.0;
132+
let num2 = 5.0;
133+
let expected = "Invalid operation".to_string();
134+
let result = calculate(operator, num1, num2);
135+
assert_eq!(result, expected);
136+
}
137+
}

Module01/Todo/Cargo.lock

-7
This file was deleted.

0 commit comments

Comments
 (0)