ralgebra/lib.rs
1//! # Roy's algebra library
2//! A very simple library made mostly
3//! to learn how to publish stuff on crates.io.
4
5/// Adds two numbers together.
6///
7/// Two lonely numbers where so very sad.
8/// One lonely number said to the other:
9/// Lets add.
10///
11/// # Examples
12/// ```
13/// let result = ralgebra::add(4, 5);
14/// assert_eq!(result, 9);
15/// ```
16pub fn add(a : i32, b : i32) -> i32 {
17 a + b
18}
19
20/// Subtracts the second number from the first one.
21///
22/// Two numbers and a minus sign walks into a bar.
23///
24/// # Examples
25/// ```
26/// let result = ralgebra::sub(9, 4);
27/// assert_eq!(result, 5);
28/// ```
29pub fn sub(a: i32, b: i32) -> i32 {
30 a - b
31}
32
33/// Multiplies two numbers.
34///
35/// Go forth and multiply, feeble numbers.
36///
37/// # Examples
38/// ```
39/// let result = ralgebra::mul(3, 6);
40/// assert_eq!(result, 18);
41/// ```
42pub fn mul(a: i32, b: i32) -> i32 {
43 a * b
44}
45
46/// Divides the first number by the second number.
47///
48/// # Examples
49///
50/// ```
51/// let result = ralgebra::div(8, 2);
52/// assert_eq!(result, 4);
53/// ```
54pub fn div(a: i32, b: i32) -> i32 {
55 a / b
56}
57
58#[cfg(test)]
59mod tests {
60 use crate::*;
61 #[test]
62 fn test_add() {
63 assert_eq!(add(2, 2), 4);
64 }
65
66 #[test]
67 fn test_sub() {
68 assert_eq!(sub(4, 2), 2);
69 }
70
71 #[test]
72 fn test_mul() {
73 assert_eq!(mul(2, 3), 6);
74 }
75
76 #[test]
77 fn test_div() {
78 assert_eq!(div(36, 6), 6);
79 }
80}