Skip to content
Snippets Groups Projects
Commit 379b1b7b authored by Michael Hauspie's avatar Michael Hauspie
Browse files

Add Fois, Diviser

parent 6f2210b1
No related branches found
No related tags found
No related merge requests found
...@@ -94,4 +94,22 @@ mod tests { ...@@ -94,4 +94,22 @@ mod tests {
assert_eq!(response, expected); assert_eq!(response, expected);
} }
#[test]
fn fois() {
let (status, response) = build_response(Operation::Fois(10, 20));
assert_eq!(status, Status::Ok);
let expected = OperationResult::new("10 x 20", 200);
assert_eq!(response, expected);
}
#[test]
fn diviser() {
let (status, response) = build_response(Operation::Diviser(10, 20));
assert_eq!(status, Status::Ok);
let expected = OperationResult::new("10 / 20", 0);
assert_eq!(response, expected);
}
} }
...@@ -8,6 +8,8 @@ use serde::{Deserialize, Serialize}; ...@@ -8,6 +8,8 @@ use serde::{Deserialize, Serialize};
pub enum Operation { pub enum Operation {
Plus(i32,i32), Plus(i32,i32),
Moins(i32,i32), Moins(i32,i32),
Fois(i32,i32),
Diviser(i32,i32),
} }
#[derive(Deserialize, Serialize, PartialEq, Debug)] #[derive(Deserialize, Serialize, PartialEq, Debug)]
...@@ -37,6 +39,14 @@ impl From<&Operation> for OperationResult { ...@@ -37,6 +39,14 @@ impl From<&Operation> for OperationResult {
operation: format!("{op1} - {op2}"), operation: format!("{op1} - {op2}"),
resultat: op1 - op2, resultat: op1 - op2,
}, },
Operation::Fois(op1, op2) => OperationResult {
operation: format!("{op1} x {op2}"),
resultat: op1 * op2,
},
Operation::Diviser(op1, op2) => OperationResult {
operation: format!("{op1} / {op2}"),
resultat: op1 / op2,
},
} }
} }
} }
...@@ -70,4 +80,22 @@ mod tests { ...@@ -70,4 +80,22 @@ mod tests {
assert_eq!(result, expected); assert_eq!(result, expected);
} }
#[test]
fn fois() {
let operation = Operation::Fois(4, 5);
let result = OperationResult::from(operation);
let expected = OperationResult::new("4 x 5", 20);
assert_eq!(result, expected);
}
#[test]
fn diviser() {
let operation = Operation::Diviser(20, 4);
let result = OperationResult::from(operation);
let expected = OperationResult::new("20 / 4", 5);
assert_eq!(result, expected);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment