|
1 | 1 | package neqsim.thermodynamicoperations.phaseenvelopeops.multicomponentenvelopeops; |
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; |
5 | 6 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
6 | 7 | import static org.junit.jupiter.api.Assertions.assertNull; |
@@ -583,4 +584,54 @@ void testQualityLinesBubbleFirst() { |
583 | 584 | assertTrue(qT25.length > 3, "Quality line 0.25 should have > 3 points"); |
584 | 585 | assertTrue(qT75.length > 3, "Quality line 0.75 should have > 3 points"); |
585 | 586 | } |
| 587 | + |
| 588 | + /** |
| 589 | + * Test that the get(String, double[]) overload returns results when the key exists and returns |
| 590 | + * the default array when the key is absent or maps to null. This enables the Python/JPype idiom |
| 591 | + * {@code pe_data.get("dewT", [])} that previously threw a JPype overload resolution error. |
| 592 | + */ |
| 593 | + @Test |
| 594 | + void testGetWithDefault() { |
| 595 | + neqsim.thermo.system.SystemInterface testSystem = |
| 596 | + new neqsim.thermo.system.SystemSrkEos(298.0, 50.0); |
| 597 | + testSystem.addComponent("nitrogen", 0.01); |
| 598 | + testSystem.addComponent("CO2", 0.01); |
| 599 | + testSystem.addComponent("methane", 0.98); |
| 600 | + testSystem.setMixingRule("classic"); |
| 601 | + |
| 602 | + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); |
| 603 | + testOps.TPflash(); |
| 604 | + testSystem.initProperties(); |
| 605 | + testOps.calcPTphaseEnvelope(); |
| 606 | + |
| 607 | + double[] emptyDefault = new double[0]; |
| 608 | + |
| 609 | + // Existing key should return actual data, not the default |
| 610 | + double[] dewT = testOps.get("dewT", emptyDefault); |
| 611 | + assertNotNull(dewT, "dewT with default should not be null"); |
| 612 | + assertTrue(dewT.length > 0, "dewT should have data points"); |
| 613 | + assertTrue(dewT != emptyDefault, "dewT should be the actual array, not the default"); |
| 614 | + |
| 615 | + double[] dewP = testOps.get("dewP", emptyDefault); |
| 616 | + assertNotNull(dewP, "dewP with default should not be null"); |
| 617 | + assertTrue(dewP.length > 0, "dewP should have data points"); |
| 618 | + |
| 619 | + // Absent key should return the default |
| 620 | + double[] unknown = testOps.get("nonExistentKey", emptyDefault); |
| 621 | + assertArrayEquals(emptyDefault, unknown, "Absent key should return the default array"); |
| 622 | + |
| 623 | + // Key that maps to null (e.g. dewT2) should return the default |
| 624 | + double[] dewT2 = testOps.get("dewT2", emptyDefault); |
| 625 | + assertArrayEquals(emptyDefault, dewT2, "dewT2 (null) should return the default array"); |
| 626 | + |
| 627 | + // Also test via the OperationInterface directly |
| 628 | + PTPhaseEnvelopeMichelsen env = (PTPhaseEnvelopeMichelsen) testOps.getOperation(); |
| 629 | + double[] bubP = env.get("bubP", emptyDefault); |
| 630 | + assertNotNull(bubP, "bubP via operation with default should not be null"); |
| 631 | + assertTrue(bubP.length > 0, "bubP should have data points"); |
| 632 | + |
| 633 | + double[] missing = env.get("noSuchKey", emptyDefault); |
| 634 | + assertArrayEquals(emptyDefault, missing, |
| 635 | + "Absent key via operation should return the default array"); |
| 636 | + } |
586 | 637 | } |
0 commit comments