use std::env;

fn main() {
    // Collect our arguments into a vector
    let args: Vec<String> = env::args().collect();
    let temp: f64 = args[1].parse().expect("Number");
    let specifier: char = args[2].parse().expect("not a char");

    let res = match specifier {
        'c' => to_fahrenheit(temp),
        'f' => to_celsius(temp),
        _ => panic!("Not ok")
    };

    println!("Converted temp is: {:?}", res);
}

fn to_celsius(temp: f64) -> f64 {
    (temp - 32.) * (5.0 / 9.0)
}

fn to_fahrenheit(temp: f64) -> f64 {
    temp / 5.0 * 9.0 + 32.
}

#[test]
fn test_f_to_c() {
    let mynum = 32.;
    let expected = 0.;

    assert_eq!(to_celsius(mynum), expected);
}

#[test]
fn test_f_to_c_boiling() {
    assert_eq!(to_celsius(212.), 100.);
}

#[test]
fn test_c_to_f() {
    assert_eq!(to_fahrenheit(100.), 212.);
    assert_eq!(to_fahrenheit(0.), 32.);
}