From c4a6b2564b89b739d300a6e6fb73e5fa2bf41206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Mon, 21 Feb 2022 15:01:11 +0100 Subject: [PATCH 1/3] chore: wrote assertEquals in the correct order --- .../compressor/CompressorTest.java | 10 ++-- .../ProcessSystemRunTransientTest.java | 2 +- .../processSystem/ProcessSystemTest.java | 46 +++++++++---------- .../util/example/process1Test.java | 3 +- .../system/SystemElectrolyteCPATest.java | 4 +- .../neqsim/thermo/system/SystemPrEosTest.java | 12 +++-- .../system/SystemSrkCPAstatoilTest.java | 12 ++--- .../system/SystemUMRPRUMCEosNewTest.java | 6 ++- .../thermo/util/example/SrkEoSTest.java | 14 +++--- .../ThermodynamicOperationsTest.java | 6 ++- 10 files changed, 59 insertions(+), 56 deletions(-) diff --git a/src/test/java/neqsim/processSimulation/processEquipment/compressor/CompressorTest.java b/src/test/java/neqsim/processSimulation/processEquipment/compressor/CompressorTest.java index 82d915a3ee..9df757cb37 100644 --- a/src/test/java/neqsim/processSimulation/processEquipment/compressor/CompressorTest.java +++ b/src/test/java/neqsim/processSimulation/processEquipment/compressor/CompressorTest.java @@ -99,7 +99,7 @@ public void testCompressorSchultzMethod() { processOps.run(); // System.out.println("schultz compressor power " + compressor1.getPower() / 1e6 // + " MW"); - assertEquals(compressor1.getPower() / 1e6, 4.668373797540108, + assertEquals(4.668373797540108, compressor1.getPower() / 1e6, "Test case for compressor Schultz method polytropic calculation should return approximate 4.67 MW"); } @@ -116,7 +116,7 @@ public void testCompressorRigorousMethod() { processOps.run(); // System.out.println("rigorous compressor power " + compressor1.getPower() / // 1e6 + " MW"); - assertEquals(compressor1.getPower() / 1e6, 4.655081035416562, + assertEquals(4.655081035416562, compressor1.getPower() / 1e6, "Test case for rigorous polytropic compressor calculation should return approximate 4.66 MW"); } @@ -132,7 +132,7 @@ public void testIsentropicCalcMethod() { processOps.run(); // System.out.println("compressor power " + compressor1.getPower() / 1e6 + " // MW"); - assertEquals(compressor1.getPower() / 1e6, 4.5621157449685); + assertEquals(4.5621157449685, compressor1.getPower() / 1e6); } /** @@ -159,7 +159,7 @@ public void testCompressorWithSrk() { // System.out.println("srk fluid head " + compressor1.getPolytropicFluidHead() + // " kJ/kg"); // System.out.println("srk power " + compressor1.getPower() + " W"); - assertEquals(compressor1.getPolytropicEfficiency() * 100, 88.94871563458828, + assertEquals(88.94871563458828, compressor1.getPolytropicEfficiency() * 100, "Test case for rigorous polytropic efficiency with SRK calculation should return approximate 88.948715 "); } @@ -189,7 +189,7 @@ public void testCompressorWithGERG2008() { // System.out.println("gerg fluid head " + compressor1.getPolytropicFluidHead() // + " kJ/kg"); // System.out.println("gerg power " + compressor1.getPower() + " W"); - assertEquals(compressor1.getPolytropicEfficiency() * 100, 89.99367027631443, + assertEquals(89.99367027631443, compressor1.getPolytropicEfficiency() * 100, "Test case for rigorous polytropic efficiency with GER2008 calculation should return approximate 89.992296751"); } } diff --git a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java index 0db71fa1be..b86bd144ff 100644 --- a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java +++ b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java @@ -26,7 +26,7 @@ public void setUp() { public void testGetName() { String name = "TestProsess"; p.setName(name); - Assertions.assertEquals(p.getName(), name); + Assertions.assertEquals(name, p.getName()); } @Test diff --git a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemTest.java b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemTest.java index dc33967797..c5e88ed466 100644 --- a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemTest.java +++ b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemTest.java @@ -28,12 +28,12 @@ void testGetName() { @Test public void testSetTimeStep() { double timeStep = p.getTimeStep() * 2; - Assertions.assertEquals(p.getTimeStep(), timeStep / 2); - Assertions.assertNotEquals(p.getTimeStep(), timeStep); + Assertions.assertEquals(timeStep / 2, p.getTimeStep()); + Assertions.assertNotEquals(timeStep, p.getTimeStep()); p.setTimeStep(timeStep); - Assertions.assertEquals(p.getTimeStep(), timeStep); - Assertions.assertNotEquals(p.getTimeStep(), timeStep / 2); + Assertions.assertEquals(timeStep, p.getTimeStep()); + Assertions.assertNotEquals(timeStep / 2, p.getTimeStep()); } @Test @@ -55,30 +55,30 @@ void testAdd() { Assertions.assertTrue(sep == p.getUnit(sepName)); - Assertions.assertEquals(list.size(), 1); - Assertions.assertEquals(p.size(), 1); + Assertions.assertEquals(1, list.size()); + Assertions.assertEquals(1, p.size()); Assertions.assertTrue((Separator) list.get(0) == sep); p.removeUnit(sepName); Assertions.assertNull(p.getUnit(sepName)); - Assertions.assertEquals(p.size(), 0); + Assertions.assertEquals(0, p.size()); list = p.getUnitOperations(); - Assertions.assertEquals(list.size(), 0); + Assertions.assertEquals(0, list.size()); p.add(sep); - Assertions.assertEquals(p.size(), 1); + Assertions.assertEquals(1, p.size()); p.clear(); - Assertions.assertEquals(p.size(), 0); + Assertions.assertEquals(0, p.size()); p.add(sep); - Assertions.assertEquals(p.size(), 1); + Assertions.assertEquals(1, p.size()); p.clearAll(); - Assertions.assertEquals(p.size(), 0); + Assertions.assertEquals(0, p.size()); } @Test @@ -86,16 +86,16 @@ public void testAddUnitTwice() { Separator sep = new Separator(); p.add(sep); p.add(sep); // Won't add the copy - Assertions.assertEquals(p.size(), 1); + Assertions.assertEquals(1, p.size()); } @Test public void testRemoveUnit() { Separator sep = new Separator(); p.add(sep); - Assertions.assertEquals(p.size(), 1); + Assertions.assertEquals(1, p.size()); p.removeUnit(""); - Assertions.assertEquals(p.size(), 0); + Assertions.assertEquals(0, p.size()); } @@ -105,11 +105,11 @@ public void testAddUnitsWithNoName() { p.add(sep); sep = new Separator(); p.add(sep); - Assertions.assertEquals(p.size(), 2); + Assertions.assertEquals(2, p.size()); p.removeUnit("Separator2"); - Assertions.assertEquals(p.size(), 1); + Assertions.assertEquals(1, p.size()); p.removeUnit(""); - Assertions.assertEquals(p.size(), 0); + Assertions.assertEquals(0, p.size()); } @Test @@ -119,21 +119,21 @@ public void testGetUnitNumber() { Separator sep2 = new Separator(); p.add(sep2); - Assertions.assertEquals(p.getUnitNumber(""), 0); - Assertions.assertEquals(p.getUnitNumber("Separator2"), 1); + Assertions.assertEquals(0, p.getUnitNumber("")); + Assertions.assertEquals(1, p.getUnitNumber("Separator2")); p.removeUnit(""); p.add(sep); - Assertions.assertEquals(p.getUnitNumber("Separator2"), 0); - Assertions.assertEquals(p.getUnitNumber(""), 1); + Assertions.assertEquals(0, p.getUnitNumber("Separator2")); + Assertions.assertEquals(1, p.getUnitNumber("")); } @Test public void testSetSurroundingTemperature() { double temp = 200; p.setSurroundingTemperature(temp); - Assertions.assertEquals(p.getSurroundingTemperature(), temp); + Assertions.assertEquals(temp, p.getSurroundingTemperature()); } @Test diff --git a/src/test/java/neqsim/processSimulation/util/example/process1Test.java b/src/test/java/neqsim/processSimulation/util/example/process1Test.java index 66bb779e99..8eedd39967 100644 --- a/src/test/java/neqsim/processSimulation/util/example/process1Test.java +++ b/src/test/java/neqsim/processSimulation/util/example/process1Test.java @@ -1,9 +1,9 @@ package neqsim.processSimulation.util.example; -import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; + import neqsim.processSimulation.processEquipment.stream.Stream; class process1Test { @@ -48,6 +48,5 @@ void tearDown() throws Exception {} @Test void runTest() { operations.run(); - assertEquals(2, 2); } } diff --git a/src/test/java/neqsim/thermo/system/SystemElectrolyteCPATest.java b/src/test/java/neqsim/thermo/system/SystemElectrolyteCPATest.java index 08f7b610ef..fada370ce9 100644 --- a/src/test/java/neqsim/thermo/system/SystemElectrolyteCPATest.java +++ b/src/test/java/neqsim/thermo/system/SystemElectrolyteCPATest.java @@ -1,10 +1,12 @@ package neqsim.thermo.system; import static org.junit.jupiter.api.Assertions.assertEquals; + import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + import neqsim.thermodynamicOperations.ThermodynamicOperations; /** @@ -55,7 +57,7 @@ public void testTPflash() { thermoSystem.init(); testOps.TPflash(); - assertEquals(thermoSystem.getNumberOfPhases(), 2); + assertEquals(2, thermoSystem.getNumberOfPhases()); } /** diff --git a/src/test/java/neqsim/thermo/system/SystemPrEosTest.java b/src/test/java/neqsim/thermo/system/SystemPrEosTest.java index ad7e26844a..ceaf6c78e2 100644 --- a/src/test/java/neqsim/thermo/system/SystemPrEosTest.java +++ b/src/test/java/neqsim/thermo/system/SystemPrEosTest.java @@ -2,9 +2,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; + import neqsim.thermodynamicOperations.ThermodynamicOperations; class SystemPrEoSTest { @@ -39,7 +41,7 @@ public static void setUp() { @Test @DisplayName("test a TPflash2") public void testTPflash2() { - assertEquals(testSystem.getNumberOfPhases(), 2); + assertEquals(2, testSystem.getNumberOfPhases()); } /** @@ -50,7 +52,7 @@ public void testTPflash2() { @Test @DisplayName("test a TPflash of the fluid (should return two phases)") public void testTPflash() { - assertEquals(testSystem.getNumberOfPhases(), 2); + assertEquals(2, testSystem.getNumberOfPhases()); } /** @@ -116,7 +118,7 @@ public void checkFugacityCoefficientsDn2() { @Test @DisplayName("calculate compressibility of gas phase") public void checkCompressibility() { - assertEquals(testSystem.getPhase("gas").getZ(), 0.9708455641951108, 1e-5); + assertEquals(0.9708455641951108, testSystem.getPhase("gas").getZ(), 1e-5); } /** @@ -131,7 +133,7 @@ public void calcProperties() { ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); testOps.TPflash(); testSystem.initProperties(); - assertEquals(testSystem.getEnthalpy("kJ/kg"), -165.60627184389855, - Math.abs(-165.60627184389855 / 1000.0)); + assertEquals(-165.60627184389855, + Math.abs(-165.60627184389855 / 1000.0), testSystem.getEnthalpy("kJ/kg")); } } diff --git a/src/test/java/neqsim/thermo/system/SystemSrkCPAstatoilTest.java b/src/test/java/neqsim/thermo/system/SystemSrkCPAstatoilTest.java index 985feb00b4..6478cd4682 100644 --- a/src/test/java/neqsim/thermo/system/SystemSrkCPAstatoilTest.java +++ b/src/test/java/neqsim/thermo/system/SystemSrkCPAstatoilTest.java @@ -1,9 +1,11 @@ package neqsim.thermo.system; import static org.junit.jupiter.api.Assertions.assertEquals; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + import neqsim.thermodynamicOperations.ThermodynamicOperations; /** @@ -43,7 +45,7 @@ public static void setUp() { public void testTPflash() { ThermodynamicOperations testOps = new ThermodynamicOperations(thermoSystem); testOps.TPflash(); - assertEquals(thermoSystem.getNumberOfPhases(), 2); + assertEquals(2, thermoSystem.getNumberOfPhases()); } /** @@ -72,9 +74,7 @@ public void testPHflash() { testOps.PHflash(enthalpy + 10.0); thermoSystem.init(3); - double enthalpy2 = thermoSystem.getEnthalpy(); - - assertEquals(Math.round(enthalpy + 10.0), Math.round(enthalpy2)); + assertEquals(Math.round(enthalpy + 10.0), Math.round(thermoSystem.getEnthalpy())); } /** @@ -91,8 +91,6 @@ public void testPSflash() { testOps.PSflash(entropy + 10.0); thermoSystem.init(3); - double entropy2 = thermoSystem.getEntropy(); - - assertEquals(Math.round(entropy + 10.0), Math.round(entropy2)); + assertEquals(Math.round(entropy + 10.0), Math.round(thermoSystem.getEntropy())); } } diff --git a/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java b/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java index 7f615e8a6a..0ee0d476f7 100644 --- a/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java +++ b/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java @@ -2,10 +2,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; + import neqsim.thermodynamicOperations.ThermodynamicOperations; @Disabled @@ -44,7 +46,7 @@ public static void setUp() { @Test @DisplayName("test a TPflash2") public void testTPflash2() { - assertEquals(testSystem.getNumberOfPhases(), 2); + assertEquals(2, testSystem.getNumberOfPhases()); } /** @@ -55,7 +57,7 @@ public void testTPflash2() { @Test @DisplayName("test a TPflash of the fluid (should return two phases)") public void testTPflash() { - assertEquals(testSystem.getNumberOfPhases(), 2); + assertEquals(2, testSystem.getNumberOfPhases()); } /** diff --git a/src/test/java/neqsim/thermo/util/example/SrkEoSTest.java b/src/test/java/neqsim/thermo/util/example/SrkEoSTest.java index 761a59f6ab..d7ffaeb0e4 100644 --- a/src/test/java/neqsim/thermo/util/example/SrkEoSTest.java +++ b/src/test/java/neqsim/thermo/util/example/SrkEoSTest.java @@ -2,12 +2,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + import neqsim.thermo.system.SystemInterface; import neqsim.thermo.system.SystemSrkEos; import neqsim.thermodynamicOperations.ThermodynamicOperations; -import org.junit.jupiter.api.Disabled; /** *

@@ -47,7 +49,7 @@ public static void setUp() { public void testTPflash() { ThermodynamicOperations testOps = new ThermodynamicOperations(thermoSystem); testOps.TPflash(); - assertEquals(thermoSystem.getNumberOfPhases(), 2); + assertEquals(2, thermoSystem.getNumberOfPhases()); } /** @@ -89,9 +91,7 @@ public void testPHflash() { testOps.PHflash(enthalpy + 10.0); thermoSystem.init(3); - double enthalpy2 = thermoSystem.getEnthalpy(); - - assertEquals(Math.round(enthalpy + 10.0), Math.round(enthalpy2)); + assertEquals(Math.round(enthalpy + 10.0), Math.round(thermoSystem.getEnthalpy())); } /** @@ -108,8 +108,6 @@ public void testPSflash() { testOps.PSflash(entropy + 10.0); thermoSystem.init(3); - double entropy2 = thermoSystem.getEntropy(); - - assertEquals(Math.round(entropy + 10.0), Math.round(entropy2)); + assertEquals(Math.round(entropy + 10.0), Math.round(thermoSystem.getEntropy())); } } diff --git a/src/test/java/neqsim/thermodynamicOperations/ThermodynamicOperationsTest.java b/src/test/java/neqsim/thermodynamicOperations/ThermodynamicOperationsTest.java index dc936e3f3d..49fc34370f 100644 --- a/src/test/java/neqsim/thermodynamicOperations/ThermodynamicOperationsTest.java +++ b/src/test/java/neqsim/thermodynamicOperations/ThermodynamicOperationsTest.java @@ -3,8 +3,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; + import neqsim.api.ioc.CalculationResult; import neqsim.thermo.system.SystemInterface; import neqsim.thermo.system.SystemSrkEos; @@ -61,7 +63,7 @@ void testpropertyFlashOnline() { ThermodynamicOperations ops = new ThermodynamicOperations(fluid); CalculationResult s = ops.propertyFlash(Arrays.asList(pressure), Arrays.asList(temperature), 1, Arrays.asList(components), onlineFractions); - Assertions.assertEquals(s.fluidProperties.length, len); + Assertions.assertEquals(len, s.fluidProperties.length); } @Test @@ -83,7 +85,7 @@ void testpropertyFlashOnlineSingle() { ThermodynamicOperations ops = new ThermodynamicOperations(fluid); CalculationResult s = ops.propertyFlash(Arrays.asList(pressure), Arrays.asList(temperature), 1, Arrays.asList(components), onlineFractions); - Assertions.assertEquals(s.fluidProperties.length, len); + Assertions.assertEquals(len, s.fluidProperties.length); } private List> createDummyRequest(double[] fractions, int len) { From eff3fbecc21fcfb29385dedc00865d0f4130f376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Mon, 21 Feb 2022 15:06:19 +0100 Subject: [PATCH 2/3] wip --- .../util/example/SrkOilCharacterizationTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/test/java/neqsim/thermo/util/example/SrkOilCharacterizationTest.java b/src/test/java/neqsim/thermo/util/example/SrkOilCharacterizationTest.java index 512dd9a8d5..de27700fa4 100644 --- a/src/test/java/neqsim/thermo/util/example/SrkOilCharacterizationTest.java +++ b/src/test/java/neqsim/thermo/util/example/SrkOilCharacterizationTest.java @@ -1,8 +1,10 @@ package neqsim.thermo.util.example; import static org.junit.jupiter.api.Assertions.assertEquals; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; + import neqsim.thermo.system.SystemInterface; // import junit.framework.TestCase; import neqsim.thermo.system.SystemSrkEos; @@ -46,7 +48,7 @@ public static void setUp() { public void testTPflash() { ThermodynamicOperations testOps = new ThermodynamicOperations(thermoSystem); testOps.TPflash(); - assertEquals(thermoSystem.getNumberOfPhases(), 2); + assertEquals(2, thermoSystem.getNumberOfPhases()); } /** @@ -71,9 +73,7 @@ public void testPHflash() { testOps.PHflash(enthalpy + 10.0); thermoSystem.init(3); - double enthalpy2 = thermoSystem.getEnthalpy(); - - assertEquals(Math.round(enthalpy + 10.0), Math.round(enthalpy2)); + assertEquals(Math.round(enthalpy + 10.0), Math.round(thermoSystem.getEnthalpy())); } /** @@ -87,7 +87,6 @@ public void testPSflash() { double entropy = thermoSystem.getEntropy(); testOps.PSflash(entropy + 10.0); thermoSystem.init(3); - double entropy2 = thermoSystem.getEntropy(); - assertEquals(Math.round(entropy + 10.0), Math.round(entropy2)); + assertEquals(Math.round(entropy + 10.0), Math.round(thermoSystem.getEntropy())); } } From afc2414b6c1d348dd9a12a48dd33277d8a99d31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Mon, 21 Feb 2022 15:13:13 +0100 Subject: [PATCH 3/3] bugfix --- src/test/java/neqsim/thermo/system/SystemPrEosTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/neqsim/thermo/system/SystemPrEosTest.java b/src/test/java/neqsim/thermo/system/SystemPrEosTest.java index ceaf6c78e2..d472216f63 100644 --- a/src/test/java/neqsim/thermo/system/SystemPrEosTest.java +++ b/src/test/java/neqsim/thermo/system/SystemPrEosTest.java @@ -133,7 +133,7 @@ public void calcProperties() { ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); testOps.TPflash(); testSystem.initProperties(); - assertEquals(-165.60627184389855, - Math.abs(-165.60627184389855 / 1000.0), testSystem.getEnthalpy("kJ/kg")); + assertEquals(-165.60627184389855, testSystem.getEnthalpy("kJ/kg"), + Math.abs(-165.60627184389855 / 1000.0)); } }