binnev_rust_template/
lib.rs

1#[doc = include_str!("../docs/ref/add.md")]
2pub fn add(a: f64, b: f64) -> f64 {
3    a + b
4}
5
6#[doc = include_str!("../docs/ref/subtract.md")]
7pub fn subtract(a: f64, b: f64) -> f64 {
8    a - b
9}
10
11#[doc = include_str!("../docs/ref/multiply.md")]
12pub fn multiply(a: f64, b: f64) -> f64 {
13    a * b
14}
15
16/// You can also put your docstring inline, but then you can't show it in the
17/// mkdocs site.
18///
19/// Divides the first number by the second and returns the result.
20///
21/// # Panics
22///
23/// Panics if the second number is zero.
24///
25/// # Examples
26///
27/// ```
28/// let result = binnev_rust_template::divide(6.0, 3.0);
29/// assert_eq!(result, 2.0);
30/// ```
31pub fn divide(a: f64, b: f64) -> f64 {
32    if b == 0.0 {
33        panic!("Cannot divide by zero");
34    }
35    a / b
36}
37
38#[cfg(test)]
39mod tests {
40    use super::*;
41
42    #[test]
43    fn test_add() {
44        assert_eq!(add(2.0, 3.0), 5.0);
45    }
46
47    #[test]
48    fn test_subtract() {
49        assert_eq!(subtract(5.0, 3.0), 2.0);
50    }
51
52    #[test]
53    fn test_multiply() {
54        assert_eq!(multiply(2.0, 3.0), 6.0);
55    }
56
57    #[test]
58    fn test_divide() {
59        assert_eq!(divide(6.0, 3.0), 2.0);
60    }
61
62    #[test]
63    #[should_panic(expected = "Cannot divide by zero")]
64    fn test_divide_by_zero() {
65        divide(1.0, 0.0);
66    }
67}