@@ -8171,6 +8171,34 @@ def test_CompositePotential_explicit_units():
81718171 return None
81728172
81738173
8174+ def test_planarCompositePotential_explicit_units ():
8175+ # Test that explicit ro/vo initialization works correctly
8176+ from galpy .potential import LogarithmicHaloPotential , planarCompositePotential
8177+
8178+ pot1 = LogarithmicHaloPotential (normalize = 0.5 ).toPlanar ()
8179+ pot2 = LogarithmicHaloPotential (normalize = 0.5 ).toPlanar ()
8180+
8181+ # Create CompositePotential with explicit ro and vo
8182+ comp = planarCompositePotential (pot1 , pot2 , ro = 8.5 , vo = 220.0 )
8183+ # Check that ro and vo are set correctly
8184+ assert comp ._ro == 8.5 , "Explicit ro not set correctly"
8185+ assert comp ._vo == 220.0 , "Explicit vo not set correctly"
8186+ assert comp ._roSet , "roSet should be True when ro is explicitly provided"
8187+ assert comp ._voSet , "voSet should be True when vo is explicitly provided"
8188+
8189+ # Test with only ro set
8190+ comp_ro = planarCompositePotential (pot1 , pot2 , ro = 9.0 )
8191+ assert comp_ro ._ro == 9.0 , "Explicit ro not set correctly"
8192+ assert comp_ro ._roSet , "roSet should be True when ro is explicitly provided"
8193+
8194+ # Test with only vo set
8195+ comp_vo = planarCompositePotential (pot1 , pot2 , vo = 230.0 )
8196+ assert comp_vo ._vo == 230.0 , "Explicit vo not set correctly"
8197+ assert comp_vo ._voSet , "voSet should be True when vo is explicitly provided"
8198+
8199+ return None
8200+
8201+
81748202def test_CompositePotential_setitem_error ():
81758203 # Test that __setitem__ raises TypeError for non-Potential values
81768204 from galpy .potential import CompositePotential , LogarithmicHaloPotential
@@ -8563,8 +8591,10 @@ def test_planarCompositePotential_from_addition():
85638591 # Create planar potentials
85648592 pot1 = MiyamotoNagaiPotential (normalize = 0.6 )
85658593 pot2 = LogarithmicHaloPotential (normalize = 0.4 )
8594+ pot3 = LogarithmicHaloPotential (normalize = 0.2 )
85668595 planar1 = toPlanarPotential (pot1 )
85678596 planar2 = toPlanarPotential (pot2 )
8597+ planar3 = toPlanarPotential (pot3 )
85688598
85698599 # Add them together
85708600 combined = planar1 + planar2
@@ -8582,6 +8612,51 @@ def test_planarCompositePotential_from_addition():
85828612 "planarCompositePotential from addition evaluates incorrectly"
85838613 )
85848614
8615+ # Some further testing copied from CompositePotential
8616+ # Test adding individual to planarCompositePotential
8617+ comp12 = planar1 + planar2
8618+ comp123 = comp12 + planar3
8619+ assert len (comp123 ) == 3
8620+ assert comp123 [0 ] == planar1
8621+ assert comp123 [1 ] == planar2
8622+ assert comp123 [2 ] == planar3
8623+
8624+ # Test adding planarCompositePotential to individual
8625+ comp23 = planar2 + planar3
8626+ comp123_2 = planar1 + comp23
8627+ assert len (comp123_2 ) == 3
8628+ assert comp123_2 [0 ] == planar1
8629+
8630+ # Test adding two planarCompositePotentials
8631+ comp12 = planar1 + planar2
8632+ comp3 = planar3 + planar3
8633+ comp_all = comp12 + comp3
8634+ assert len (comp_all ) == 4
8635+ return None
8636+
8637+
8638+ def test_planarCompositePotential_add_error ():
8639+ # Test that __add__ raises TypeError for incompatible types
8640+ from galpy .potential import LogarithmicHaloPotential , planarCompositePotential
8641+
8642+ pot1 = LogarithmicHaloPotential (normalize = 0.5 ).toPlanar ()
8643+ pot2 = LogarithmicHaloPotential (normalize = 0.5 ).toPlanar ()
8644+ comp = planarCompositePotential (pot1 , pot2 )
8645+
8646+ # Try to add a string
8647+ try :
8648+ result = comp + "not a potential"
8649+ assert False , "Should have raised TypeError"
8650+ except TypeError as e :
8651+ assert "Can only add planarPotential" in str (e )
8652+
8653+ # Try to add a number
8654+ try :
8655+ result = comp + 42
8656+ assert False , "Should have raised TypeError"
8657+ except TypeError as e :
8658+ assert "Can only add planarPotential" in str (e )
8659+
85858660 return None
85868661
85878662
0 commit comments