From 8f77a9b234ca808ec1167306cd99a48816d43ae8 Mon Sep 17 00:00:00 2001
From: Vladimir Portyanikhin <86243191+portyanikhin@users.noreply.github.com>
Date: Wed, 18 Dec 2024 18:26:02 +0300
Subject: [PATCH] Fix `HumidAir.Mixing` method

---
 src/SharpProp/HumidAir/HumidAirProcesses.cs   | 20 +++++++++++++++----
 .../HumidAir/HumidAirProcessesTests.cs        | 17 +++++++++++++++-
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/src/SharpProp/HumidAir/HumidAirProcesses.cs b/src/SharpProp/HumidAir/HumidAirProcesses.cs
index 06878eb..c20ee98 100644
--- a/src/SharpProp/HumidAir/HumidAirProcesses.cs
+++ b/src/SharpProp/HumidAir/HumidAirProcesses.cs
@@ -101,10 +101,22 @@ IHumidAir second
                     ) / (firstSpecificMassFlow + secondSpecificMassFlow).DecimalFractions
                 ),
                 InputHumidAir.Humidity(
-                    (
-                        firstSpecificMassFlow.DecimalFractions * first.Humidity
-                        + secondSpecificMassFlow.DecimalFractions * second.Humidity
-                    ) / (firstSpecificMassFlow + secondSpecificMassFlow).DecimalFractions
+                    Ratio.FromDecimalFractions(
+                        (
+                            firstSpecificMassFlow.DecimalFractions
+                                * first.Humidity.DecimalFractions
+                                * (1 + second.Humidity.DecimalFractions)
+                            + secondSpecificMassFlow.DecimalFractions
+                                * second.Humidity.DecimalFractions
+                                * (1 + first.Humidity.DecimalFractions)
+                        )
+                            / (
+                                firstSpecificMassFlow.DecimalFractions
+                                    * (1 + second.Humidity.DecimalFractions)
+                                + secondSpecificMassFlow.DecimalFractions
+                                    * (1 + first.Humidity.DecimalFractions)
+                            )
+                    )
                 )
             )
             : throw new ArgumentException(
diff --git a/tests/SharpProp.Tests/HumidAir/HumidAirProcessesTests.cs b/tests/SharpProp.Tests/HumidAir/HumidAirProcessesTests.cs
index be89eb7..af0eb0b 100644
--- a/tests/SharpProp.Tests/HumidAir/HumidAirProcessesTests.cs
+++ b/tests/SharpProp.Tests/HumidAir/HumidAirProcessesTests.cs
@@ -426,7 +426,22 @@ public void Mixing_SamePressures_ReturnsMixPoint()
                 _humidAir.WithState(
                     InputHumidAir.Pressure(_humidAir.Pressure),
                     InputHumidAir.Enthalpy((1 * first.Enthalpy + 2 * second.Enthalpy) / 3.0),
-                    InputHumidAir.Humidity((1 * first.Humidity + 2 * second.Humidity) / 3.0)
+                    InputHumidAir.Humidity(
+                        Ratio.FromDecimalFractions(
+                            (
+                                1
+                                    * first.Humidity.DecimalFractions
+                                    * (1 + second.Humidity.DecimalFractions)
+                                + 2
+                                    * second.Humidity.DecimalFractions
+                                    * (1 + first.Humidity.DecimalFractions)
+                            )
+                                / (
+                                    1 * (1 + second.Humidity.DecimalFractions)
+                                    + 2 * (1 + first.Humidity.DecimalFractions)
+                                )
+                        )
+                    )
                 )
             );
     }