pub fn to_cm(inches: f64) -> f64 {
inches * 2.54
}
pub fn to_in(centimeters: f64) -> f64 {
centimeters / 2.54
}
pub fn to_kph(mph: f64) -> f64 {
mph * 1.609344
}
pub fn to_mph(kph: f64) -> f64 {
kph * 0.6214
}
pub fn mph_from_oss(oss: f64, tire_revs_per_mile: f64, axle_ratio: f64) -> f64 {
oss / axle_ratio / tire_revs_per_mile * 60.0
}
pub fn oss_from_mph(mph: f64, tire_revs_per_mile: f64, axle_ratio: f64) -> f64 {
((tire_revs_per_mile * mph) / 60.0) * axle_ratio
}
pub fn engine_rpm_from_oss(oss: f64, trans_gear_ratio: f64) -> f64 {
oss * trans_gear_ratio
}
pub fn oss_from_engine_rpm(rpm: f64, trans_gear_ratio: f64) -> f64 {
rpm / trans_gear_ratio
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_to_cm() {
let inches = 1.0;
let cm = to_cm(inches);
assert!(cm == 2.54);
}
#[test]
fn test_to_in() {
let centimeters = 25.4;
let inches = to_in(centimeters);
assert!(inches == 10.0);
}
#[test]
fn test_mph_to_kph() {
let mph = 100.0;
let kph = to_kph(mph);
assert!(kph == mph * 1.609344);
}
#[test]
fn test_kph_to_mph() {
let kph = 100.0;
let mph = to_mph(kph);
assert!(mph == kph * 0.6214);
}
#[test]
fn test_mph_from_oss() {
let oss = 1000.0;
let tire_revs_per_mile = 600.0;
let axle_ratio = 3.21;
let mph = mph_from_oss(oss, tire_revs_per_mile, axle_ratio);
println!("{}mph", mph);
assert!(mph == 31.15264797507788);
}
#[test]
fn test_oss_from_mph() {
let mph = 100.0;
let tire_revs_per_mile = 600.0;
let axle_ratio = 3.21;
let oss = oss_from_mph(mph, tire_revs_per_mile, axle_ratio);
println!("{}oss", oss);
assert!(oss == 3210.0);
}
#[test]
fn test_engine_rpm_from_oss() {
let rpm = engine_rpm_from_oss(1000.0, 2.0);
assert_eq!(rpm, 2000.0);
}
#[test]
fn test_oss_from_engine_rpm() {
let oss = oss_from_engine_rpm(2000.0, 2.0);
assert_eq!(oss, 1000.0);
}
}