Skip to content

Commit

Permalink
Add add and remove extension tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Sep 26, 2024
1 parent 34b0f93 commit 43d45a4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions platypus/tests/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
EpsNSGAII, ParticleSwarm)
from ..core import Direction, Problem
from ..errors import PlatypusError
from ..extensions import LoggingExtension
from ..problems import CF1, DTLZ2
from ..weights import normal_boundary_weights, pbi
from ._utils import similar
Expand Down Expand Up @@ -100,3 +101,22 @@ def maximized_problem():
def test_fail_maximization(maximized_problem, algorithm):
with pytest.raises(PlatypusError):
algorithm(maximized_problem, **algorithms[algorithm][0])

def test_extensions():
algorithm = NSGAII(DTLZ2())

# always start with the LoggingExtension
assert len(algorithm._extensions) == 1

algorithm.remove_extension(LoggingExtension)
assert len(algorithm._extensions) == 0

l1 = LoggingExtension()
l2 = LoggingExtension()

algorithm.add_extension(l1)
algorithm.add_extension(l2)
assert [l2, l1] == algorithm._extensions

algorithm.remove_extension(l2)
assert [l1] == algorithm._extensions

0 comments on commit 43d45a4

Please sign in to comment.