1pub fn gcd(mut first: i128, mut second: i128) -> Result<i128, &'static str> {
2 if first < 0 || second < 0 {
3 return Err("Error, None of the numbers can be negative.");
4 }
5 if first < second {
6 let cash: i128 = first;
7 first = second;
8 second = cash;
9 }
10 if second == 0 {
11 return Ok(first);
12 }
13 gcd(second, first % second)
14}
15
16#[cfg(test)]
17mod tests {
18 use super::*;
19
20 #[test]
21 fn it_works() {
22 let mut result: i128 = gcd(6, 18).unwrap();
23 assert_eq!(result, 6);
24
25 result = gcd(24, 4).unwrap();
26 assert_eq!(result, 4);
27
28 let result = gcd(-10, 10);
29 assert!(result.is_err())
30 }
31}