1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
pub mod temperature_conversation {
/// # This function convert from celsius to fahrenheit
///
/// # example
///
/// ```rust
/// use utility_converter::converter;
///
/// assert_eq!(59.0, converter::celsius_to_fahrenheit(15.0));
/// assert_eq!(77.0, converter::celsius_to_fahrenheit(25.0));
/// assert_eq!(86.0, converter::celsius_to_fahrenheit(30.0));
/// ```
pub fn celsius_to_fahrenheit(celsius: f64) -> f64 {
(celsius * 9.0 / 5.0) + 32.0
}
/// # This function convert from celsius to kelvin
///
/// # example
///
/// ```rust
/// use utility_converter::converter;
///
/// assert_eq!(288.15, converter::celsius_to_kelvin(15.0));
/// assert_eq!(298.15, converter::celsius_to_kelvin(25.0));
/// assert_eq!(303.15, converter::celsius_to_kelvin(30.0));
/// ```
pub fn celsius_to_kelvin(celsius: f64) -> f64 {
celsius + 273.15
}
/// # This function convert from fahrenheit to celsius
///
/// # example
///
/// ```rust
/// use utility_converter::converter;
///
/// assert_eq!(15.0, converter::fahrenheit_to_celsius(59.0));
/// assert_eq!(25.0, converter::fahrenheit_to_celsius(77.0));
/// assert_eq!(30.0, converter::fahrenheit_to_celsius(86.0));
/// ```
pub fn fahrenheit_to_celsius(fahrenheit: f64) -> f64 {
(fahrenheit - 32.0) * 5.0 / 9.0
}
/// # This function convert from fahrenheit to kelvin
///
/// # example
///
/// ```rust
/// use utility_converter::converter;
///
/// assert_eq!(288.15, converter::fahrenheit_to_kelvin(59.0));
/// assert_eq!(298.15, converter::fahrenheit_to_kelvin(77.0));
/// assert_eq!(303.15, converter::fahrenheit_to_kelvin(86.0));
/// ```
pub fn fahrenheit_to_kelvin(fahrenheit: f64) -> f64 {
let celsius = fahrenheit_to_celsius(fahrenheit);
return celsius_to_kelvin(celsius);
}
/// # This function convert from kelvin to celsius
///
/// # example
///
/// ```rust
/// use utility_converter::converter;
///
/// assert_eq!(15.0, converter::kelvin_to_celsius(288.15));
/// assert_eq!(25.0, converter::kelvin_to_celsius(298.15));
/// assert_eq!(30.0, converter::kelvin_to_celsius(303.15));
/// ```
pub fn kelvin_to_celsius(kelvin: f64) -> f64 {
kelvin - 273.15
}
/// # This function convert from kelvin to fahrenheit
///
/// # example
///
/// ```rust
/// use utility_converter::converter;
///
/// assert_eq!(59.0, converter::kelvin_to_fahrenheit(288.15));
/// assert_eq!(77.0, converter::kelvin_to_fahrenheit(298.15));
/// assert_eq!(86.0, converter::kelvin_to_fahrenheit(303.15));
/// ```
pub fn kelvin_to_fahrenheit(kelvin: f64) -> f64 {
let celsius = kelvin_to_celsius(kelvin);
return celsius_to_fahrenheit(celsius);
}
}
#[cfg(test)]
mod test {
use super::temperature_conversation;
#[test]
fn test_celsius_to_fahrenheit() {
let result: f64 = temperature_conversation::celsius_to_fahrenheit(25.0);
let expect: f64 = 77.0;
assert_eq!(result, expect);
}
#[test]
fn test_celsius_to_kelvin() {
let result: f64 = temperature_conversation::celsius_to_kelvin(25.0);
let expect: f64 = 298.15;
assert_eq!(result, expect);
}
#[test]
fn test_fahrenheit_to_celsius() {
let result: f64 = temperature_conversation::fahrenheit_to_celsius(77.0);
let expect: f64 = 25.0;
assert_eq!(result, expect);
}
#[test]
fn test_fahrenheit_to_kelvin() {
let result: f64 = temperature_conversation::fahrenheit_to_kelvin(77.0);
let expect: f64 = 298.15;
assert_eq!(result, expect);
}
#[test]
fn test_kelvin_to_celsius() {
let result: f64 = temperature_conversation::kelvin_to_celsius(298.15);
let expect: f64 = 25.0;
assert_eq!(result, expect);
}
#[test]
fn test_kelvin_to_fahrenheit() {
let result: f64 = temperature_conversation::kelvin_to_fahrenheit(298.15);
let expect: f64 = 77.0;
assert_eq!(result, expect);
}
}