test_release_automation/
lib.rs

1//! # v0.2.*
2
3/// A simple addition function
4pub fn add(a: f64, b: f64) -> f64 {
5    a + b
6}
7
8/// A simple subtraction function
9pub fn subtract(a: f64, b: f64) -> f64 {
10    a - b
11}
12
13/// A simple multiplication function
14pub fn multiply(a: f64, b: f64) -> f64 {
15    a * b
16}
17
18/// A simple division function
19pub fn divide(a: f64, b: f64) -> f64 {
20    if b == 0.0 {
21        panic!("Cannot divide by zero");
22    }
23    a / b
24}
25
26/// Raise a number to the power of the exponent value
27pub fn power(n: f64, exp: f64) -> f64 {
28    (n as u32).pow(exp as u32) as f64
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[test]
36    fn test_add() {
37        assert_eq!(add(2.0, 3.0), 5.0);
38    }
39
40    #[test]
41    fn test_subtract() {
42        assert_eq!(subtract(5.0, 3.0), 2.0);
43    }
44
45    #[test]
46    fn test_multiply() {
47        assert_eq!(multiply(2.0, 3.0), 6.0);
48    }
49
50    #[test]
51    fn test_divide() {
52        assert_eq!(divide(6.0, 3.0), 2.0);
53    }
54
55    #[test]
56    #[should_panic(expected = "Cannot divide by zero")]
57    fn test_divide_by_zero() {
58        divide(6.0, 0.0);
59    }
60
61    #[test]
62    fn test_power() {
63        assert_eq!(power(3.0, 3.0), 27.0);
64    }
65}