test_crate_01/lib.rs
1//! # test_crate
2//!
3//! A simple crate that provides functionality for calculating the area, volume, and perimeter of a rectangle.
4//!
5
6
7/// Calculates the area of a rectangle given its length and width.
8///
9/// # Arguments
10///
11/// * `length` - The length of the rectangle.
12/// * `width` - The width of the rectangle.
13///
14/// # Returns
15///
16/// The area of the rectangle.
17///
18/// # Examples
19/// ```
20/// let result = test_crate::area(5,2);
21/// assert_eq!(result,10);
22/// ```
23pub fn area(length: usize, width: usize) -> usize {
24 length * width
25}
26
27/// Calculates the volume of a rectangular prism given its length, width, and height.
28///
29/// # Arguments
30///
31/// * `length` - The length of the rectangular prism.
32/// * `width` - The width of the rectangular prism.
33/// * `height` - The height of the rectangular prism.
34///
35/// # Returns
36///
37/// The volume of the rectangular prism.
38///
39/// # Examples
40/// ```
41/// let result = test_crate::volume(5,2,3);
42/// assert_eq!(result,30);
43/// ```
44pub fn volume(length: usize, width: usize, height: usize) -> usize {
45 length * width * height
46}
47
48/// Calculates the perimeter of a rectangle given its length and width.
49///
50/// # Arguments
51///
52/// * `length` - The length of the rectangle.
53/// * `width` - The width of the rectangle.
54///
55/// # Returns
56///
57/// The perimeter of the rectangle.
58///
59/// # Examples
60/// ```
61/// let result = test_crate::perimeter(5,2);
62/// assert_eq!(result,14);
63/// ```
64///
65pub fn perimeter(length: usize, width: usize) -> usize {
66 2 * (length + width)
67}
68
69/// Calculates the area, volume, and perimeter of a rectangle given its length, width, and height.
70///
71/// # Arguments
72///
73/// * `length` - The length of the rectangle.
74/// * `width` - The width of the rectangle.
75/// * `height` - The height of the rectangle.
76///
77/// # Returns
78///
79/// A tuple containing the area, volume, and perimeter of the rectangle.
80///
81/// # Examples
82/// ```
83/// let result = test_crate::get_data((5,2,3));
84/// assert_eq!(result,(10,30,14));
85/// ```
86pub fn get_data((length, width, height): (usize, usize, usize)) -> (usize, usize, usize) {
87 (area(length, width), volume(length, width, height), perimeter(length, width))
88}
89
90#[cfg(test)]
91mod tests {
92 use super::*;
93
94 #[test]
95 fn it_works() {
96 let result = area(5, 2);
97 assert_eq!(result, 10);
98 }
99
100 #[test]
101 fn it_works2() {
102 let result = volume(5, 2, 3);
103 assert_eq!(result, 30);
104 }
105
106 #[test]
107 fn it_works3() {
108 let result = perimeter(5, 2);
109 assert_eq!(result, 14);
110 }
111
112 #[test]
113 fn it_works4() {
114 let result = get_data((5, 2, 3));
115 assert_eq!(result, (10, 30, 14));
116 }
117}