#[test]
#[cfg(feature = "coolprop")]
fn test_mixture_glide_r454b() {
    let backend = CoolPropBackend::new();

    // R410A composition (mass fractions)
    let mixture = Mixture::from_mass_fractions(&[("R32", 0.5), ("R125", 0.5)]).unwrap();

    let p = Pressure::from_bar(10.0);

    let t_bubble = backend.bubble_point(p, &mixture).unwrap();
    let t_dew = backend.dew_point(p, &mixture).unwrap();
    let glide = backend.temperature_glide(p, &mixture).unwrap();

    // R410A is near-azeotropic, glide should be very small (< 0.2K)
    assert!(t_dew.to_kelvin() >= t_bubble.to_kelvin() - 0.1);
    assert!(glide < 0.5);
    assert_relative_eq!(
        glide,
        t_dew.to_kelvin() - t_bubble.to_kelvin(),
        epsilon = 1e-6
    );

    // Typically glide for R454B is around 1.5K at 10 bar
    assert!(glide > 0.5 && glide < 3.0);
}

#[test]
#[cfg(feature = "coolprop")]
fn test_mixture_ph_state() {
    let backend = CoolPropBackend::new();
    let mixture = Mixture::from_mass_fractions(&[("R32", 0.689), ("R1234yf", 0.311)]).unwrap();

    let p = Pressure::from_bar(10.0);

    // Middle of two-phase region (Quality ~ 0.5)
    let h_bubble = backend
        .property(
            FluidId::new("R454B"),
            Property::Enthalpy,
            FluidState::from_px_mix(p, 0.0.into(), mixture.clone()),
        )
        .unwrap();
    let h_dew = backend
        .property(
            FluidId::new("R454B"),
            Property::Enthalpy,
            FluidState::from_px_mix(p, 1.0.into(), mixture.clone()),
        )
        .unwrap();

    let h_mid = Enthalpy::from_joules_per_kg((h_bubble + h_dew) / 2.0);
    let state = FluidState::from_ph_mix(p, h_mid, mixture.clone());

    let t = backend
        .property(FluidId::new("R454B"), Property::Temperature, state)
        .unwrap();

    // Temperature in two-phase should be between bubble and dew point
    let t_bubble = backend.bubble_point(p, &mixture).unwrap();
    let t_dew = backend.dew_point(p, &mixture).unwrap();

    // Use some epsilon for equality
    assert!(t >= t_bubble.to_kelvin() - 0.5 && t <= t_dew.to_kelvin() + 0.5);
}
