1pub fn convert_celsius_to_kelvin(celsius: f64) -> f64 {
2 celsius + 273.15
3}
4
5pub fn convert_bar_to_pascal(bar: f64, decimal_places: u32) -> f64 {
6 let factor = 10f64.powi(decimal_places as i32);
7 (bar * 100_000.0 * factor).round() / factor
8}
9
10pub fn semicircles_to_degrees(semicircles: i32, decimal_places: u32) -> f64 {
11 let factor = 10f64.powi(decimal_places as i32);
12 (semicircles as f64 * (180f64 / 2f64.powi(31)) * factor).round() / factor
13}
14
15#[cfg(test)]
16mod tests {
17 use super::*;
18
19 #[test]
20 fn test_convert_celsius_to_kelvin() {
21 assert_eq!(convert_celsius_to_kelvin(0.0), 273.15);
22 assert_eq!(convert_celsius_to_kelvin(100.0), 373.15);
23 assert_eq!(convert_celsius_to_kelvin(-273.15), 0.0);
24 assert_eq!(convert_celsius_to_kelvin(25.0), 298.15);
25 }
26
27 #[test]
28 fn test_convert_bar_to_pascal() {
29 assert_eq!(convert_bar_to_pascal(1.0, 0), 100_000.0);
30 assert_eq!(convert_bar_to_pascal(0.0, 0), 0.0);
31 assert_eq!(convert_bar_to_pascal(2.0, 0), 200_000.0);
32 assert_eq!(convert_bar_to_pascal(0.5, 0), 50_000.0);
33 assert_eq!(convert_bar_to_pascal(78.57, 2), 7_857_000.0);
34 }
35
36 #[test]
37 fn test_semicircles_to_degrees() {
38 assert_eq!(semicircles_to_degrees(0, 1), 0.0);
39 assert_eq!(semicircles_to_degrees(579933426, 10), 48.6094582267);
40 assert_eq!(semicircles_to_degrees(-55384979, 10), -4.6423153114);
41 }
42}