Skip to content

Commit

Permalink
feat: SParticle and Particle conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Beforerr committed Nov 24, 2024
1 parent d770c1c commit f8cb936
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/typed_particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion test/typed_particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit f8cb936

Please sign in to comment.