-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include some special casing for chemical species
- Loading branch information
Showing
2 changed files
with
64 additions
and
66 deletions.
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 |
---|---|---|
@@ -1,33 +1,45 @@ | ||
|
||
using AtomsBase | ||
using Unitful | ||
using UnitfulAtomic | ||
using Test | ||
|
||
## | ||
|
||
@testset "ChemicalSpecies" begin | ||
|
||
symbols = [:H, :He, :Li, :Be, :B, :C, :N, :O, :F, :Ne, | ||
:Na, :Mg, :Al, :Si, :P, :S, :Cl, :Ar, :K, :Ca] | ||
|
||
# https://thechemicalelements.com/protons-neutrons-electrons-of-elements/ | ||
n_neut = [0, 2, 4, 5, 6, 6, 7, 8, 10, 10, | ||
12, 12, 14, 14, 16, 16, 18, 22, 20, 20] | ||
|
||
for z = 1:10 | ||
@test ChemicalSpecies(symbols[z]) == ChemicalSpecies(z) == ChemicalSpecies(z, n_neut[z], 0) | ||
end | ||
|
||
@test ChemicalSpecies(:D) == ChemicalSpecies(1, 1, 0) | ||
@test ChemicalSpecies(:C13) == ChemicalSpecies(6, 7, 0) | ||
|
||
@test atomic_number( UInt(8) ) == 8 | ||
@test atomic_number( Int16(12) ) == 12 | ||
|
||
@test "$(ChemicalSpecies(:O))" == "$(ChemicalSpecies(8))" == "O" | ||
@test "$(ChemicalSpecies(8, 8, 0))" == "O" | ||
@test "$(ChemicalSpecies(:C; n_neutrons=6))" == "C" | ||
@test "$(ChemicalSpecies(:C; n_neutrons=7))" == "C13" | ||
|
||
@testset "ChemicalSpecies" begin | ||
@testset "Neutron determination" begin | ||
symbols = [:H, :He, :Li, :Be, :B, :C, :N, :O, :F, :Ne, | ||
:Na, :Mg, :Al, :Si, :P, :S, :Cl, :Ar, :K, :Ca] | ||
|
||
# https://thechemicalelements.com/protons-neutrons-electrons-of-elements/ | ||
n_neut = [0, 2, 4, 5, 6, 6, 7, 8, 10, 10, | ||
12, 12, 14, 14, 16, 16, 18, 22, 20, 20] | ||
|
||
for z = 1:10 | ||
@test ChemicalSpecies(symbols[z]) == ChemicalSpecies(z) | ||
@test ChemicalSpecies(z) == ChemicalSpecies(z, n_neut[z], 0) | ||
end | ||
|
||
@test ChemicalSpecies(:D) == ChemicalSpecies(1, 1, 0) | ||
@test ChemicalSpecies(:C13) == ChemicalSpecies(6, 7, 0) | ||
end | ||
|
||
@testset "Printing" begin | ||
@test "$(ChemicalSpecies(:O))" == "$(ChemicalSpecies(8))" == "O" | ||
@test "$(ChemicalSpecies(8, 8, 0))" == "O" | ||
@test "$(ChemicalSpecies(:C; n_neutrons=6))" == "C" | ||
@test "$(ChemicalSpecies(:C; n_neutrons=7))" == "C13" | ||
end | ||
|
||
@testset "Special cases" begin | ||
# Test a few special cases that come up in the wild | ||
x = ChemicalSpecies(0) | ||
@test x.n_neutrons == 0 | ||
@test atomic_number(x) == 0 | ||
@test mass(x) == 0u"u" | ||
|
||
@test x = ChemicalSpecies(:X) | ||
end | ||
|
||
@test atomic_number( UInt(8) ) == 8 | ||
@test atomic_number( Int16(12) ) == 12 | ||
end |