diff --git a/src/typed_particles.jl b/src/typed_particles.jl index 0fd8cc0..76a819d 100644 --- a/src/typed_particles.jl +++ b/src/typed_particles.jl @@ -31,6 +31,7 @@ struct SParticle{z,Z,A} <: AbstractParticle end SParticle(z, Z, A) = SParticle{z,Z,A}() +SParticle(p::AbstractParticle) = SParticle(charge_number(p), atomic_number(p), mass_number(p)) # Basic properties - use single type parameter where possible charge_number(::SParticle{z}) where {z} = z diff --git a/test/typed_particles.jl b/test/typed_particles.jl index d4e3fef..0603719 100644 --- a/test/typed_particles.jl +++ b/test/typed_particles.jl @@ -5,9 +5,19 @@ using Test, ChargedParticles, Unitful p = SParticle(1, 2, 3) @test p isa AbstractParticle @test p isa SParticle{1,2,3} + @test p isa SParticle{1} # Test basic properties @test charge_number(p) == 1 @test atomic_number(p) == 2 @test mass_number(p) == 3 -end \ No newline at end of file +end + +@testset "SParticle and Particle" begin + p1 = Particle(:He, 1, 3) + p2 = SParticle(1, 2, 3) + p3 = SParticle(p1) + p4 = Particle(p2) + @test p3 == p2 != p1 == p4 + @test string(p1) == string(p2) +end