-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add Custom Particles test into runtest
- Loading branch information
Showing
4 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
CustomParticle <: AbstractParticle | ||
A particle with user-defined mass and charge. | ||
# Fields | ||
- `mass`: The mass of the particle (can be any numeric type or Unitful quantity) | ||
- `charge_number`: Integer representing the charge state | ||
- `symbol`: Optional symbol identifier (defaults to nothing) | ||
# Examples | ||
```julia | ||
CustomParticle(1.67e-27u"kg", 1) # A particle with proton-like mass and +1 charge | ||
CustomParticle(2.0u"GeV", -1, :custom) # A custom particle with specified symbol | ||
``` | ||
""" | ||
@kwdef struct CustomParticle <: AbstractParticle | ||
mass::Unitful.Mass | ||
charge_number::Int | ||
symbol::Symbol | ||
function CustomParticle(mass, charge_number, symbol=:custom) | ||
new(mass, charge_number, symbol) | ||
end | ||
end | ||
|
||
function CustomParticle(mass_energy::Unitful.Energy, charge_number, symbol=:custom) | ||
mass = uconvert(u"kg", mass_energy / Unitful.c^2) | ||
CustomParticle(mass, charge_number, symbol) | ||
end | ||
|
||
# Override mass method for CustomParticle | ||
mass(p::CustomParticle) = p.mass | ||
# CustomParticle doesn't have a mass number | ||
mass_number(::CustomParticle) = nothing | ||
# CustomParticle doesn't have an element | ||
element(::CustomParticle) = nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Test, ChargedParticles, Unitful | ||
using Unitful: q | ||
|
||
@testset "CustomParticle" begin | ||
# Test basic construction | ||
p1 = CustomParticle(1.67e-27u"kg", 1) | ||
@test mass(p1) == 1.67e-27u"kg" | ||
@test p1.charge_number == 1 | ||
@test p1.symbol == :custom | ||
|
||
# Test with custom symbol | ||
p2 = CustomParticle(2.0u"GeV", -1, :my_particle) | ||
@test mass_energy(p2) == 2.0u"GeV" | ||
@test charge(p2) == -Unitful.q | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters