Skip to content

Commit e7c0180

Browse files
committed
Remove unnecessary pass statements; enhance tests
1 parent 0b84a7f commit e7c0180

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/polykin/thermo/acm/base.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ def gE(self, T: Number, x: FloatVector) -> Number:
181181
float
182182
Molar excess Gibbs energy [J/mol].
183183
"""
184-
pass
185184

186185
@abstractmethod
187186
def gamma(self, T: float, x: FloatVector) -> FloatVector:
@@ -199,7 +198,6 @@ def gamma(self, T: float, x: FloatVector) -> FloatVector:
199198
FloatVector (N)
200199
Activity coefficients of all components.
201200
"""
202-
pass
203201

204202

205203
class PolymerActivityModel(ActivityModel):
@@ -428,7 +426,6 @@ def gE(
428426
float
429427
Excess Gibbs energy per mole of segments [J/mol].
430428
"""
431-
pass
432429

433430
@abstractmethod
434431
def activity(
@@ -456,4 +453,3 @@ def activity(
456453
FloatVector (N)
457454
Activities of all components.
458455
"""
459-
pass

tests/thermo/test_acm.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Copyright Hugo Vale 2024
44

55
import numpy as np
6+
import pytest
67
from numpy import allclose, isclose
78
from scipy.constants import gas_constant as R
89

@@ -16,6 +17,7 @@
1617
Wilson,
1718
)
1819
from polykin.thermo.acm.base import SmallSpeciesActivityModel
20+
from polykin.utils.exceptions import ShapeError
1921

2022

2123
def check_gE_gamma(acm: SmallSpeciesActivityModel, x, T=298):
@@ -30,6 +32,8 @@ def test_IdealSolution():
3032
T = 298.0
3133
x = np.array([0.5, 0.5])
3234
assert isclose(acm.gE(T, x), 0.0)
35+
assert isclose(acm.hE(T, x), 0.0)
36+
assert isclose(acm.sE(T, x), 0.0)
3337
assert allclose(acm.gamma(T, x), [1.0, 1.0])
3438

3539

@@ -49,6 +53,12 @@ def test_NRTL():
4953
assert allclose(acm.gamma(T, np.array([1.0, 0.0])), [1.0, 4.557085], rtol=1e-6)
5054
assert isclose(acm.Dgmix(T, np.array([0.5, 0.5])), -0.98183e3, rtol=1e-4)
5155
assert check_gE_gamma(acm, np.array([0.3, 0.7]))
56+
# trivial case: ideal solution
57+
acm = NRTL(2, name="ideal")
58+
assert isclose(acm.gE(T, x=np.array([0.4, 0.6])), 0.0)
59+
# invalid shape
60+
with pytest.raises(ShapeError):
61+
_ = NRTL(2, a=np.zeros((2, 3)), b=np.zeros((2, 2)))
5262

5363

5464
def test_UNIQUAC():
@@ -61,6 +71,11 @@ def test_UNIQUAC():
6171
T = 45 + 273.15
6272
assert allclose(acm.gamma(T, x), [7.15, 1.25, 1.06], rtol=2e-3)
6373
assert check_gE_gamma(acm, x)
74+
# invalid shape
75+
with pytest.raises(ShapeError):
76+
_ = UNIQUAC(N, q, r[0:2])
77+
with pytest.raises(ShapeError):
78+
_ = UNIQUAC(3, q, r, a=np.zeros((2, 3)))
6479

6580

6681
def test_UNIQUAC_2():
@@ -159,3 +174,9 @@ def test_Wilson():
159174
assert allclose(acm.gamma(T, np.array([1.0, 0.0])), [1.0, 4.90196], rtol=1e-6)
160175
assert isclose(acm.Dgmix(T, np.array([0.5, 0.5])), -0.983275e3, rtol=1e-4)
161176
assert check_gE_gamma(acm, x=np.array([0.4, 0.6]))
177+
# trivial case: ideal solution
178+
acm = Wilson(N, name="ideal")
179+
assert isclose(acm.gE(T, x=np.array([0.4, 0.6])), 0.0)
180+
# invalid shape
181+
with pytest.raises(ShapeError):
182+
_ = Wilson(2, a=np.zeros((2, 3)), b=np.zeros((2, 2)))

0 commit comments

Comments
 (0)