-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for
Cone
and Torus
for different cases
- Loading branch information
Showing
2 changed files
with
76 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using Test | ||
using SolidStateDetectors | ||
using StaticArrays | ||
|
||
import SolidStateDetectors.ConstructiveSolidGeometry as CSG | ||
import SolidStateDetectors.ConstructiveSolidGeometry: Geometry | ||
|
||
T = Float64 | ||
|
||
default_units = SolidStateDetectors.default_unit_tuple() | ||
no_translations = (rotation = one(SMatrix{3, 3, T, 9}), translation = zero(CartesianVector{T})) | ||
|
||
@testset "Test primitive parsing" begin | ||
@testset "Cone" begin | ||
for bot in (2.0, Dict("from" => 1.0, "to" => 2.0)), | ||
top in (2.0, 1.0, Dict("from" => 1.0, "to" => 2.0), Dict("from" => 2.0, "to" => 4.0)), | ||
φmax in (180,360) | ||
|
||
dict = Dict("difference" => [ | ||
Dict("cone" => Dict( | ||
"r" => Dict("bottom" => bot, "top" => top), | ||
"phi" => Dict("from" => "0°", "to" => "$(φmax)°"), | ||
"h" => 1.0)) | ||
for i in 1:2 | ||
]) | ||
|
||
c = Geometry(T, dict, default_units, no_translations) | ||
|
||
# No warnings or errors when decomposing the Cones into surfaces | ||
@test_nowarn CSG.surfaces(c.a) | ||
@test_nowarn CSG.surfaces(c.b) | ||
|
||
# Check if all Cones are saved the right way | ||
@test c.a isa CSG.Cone | ||
@test c.b isa CSG.Cone | ||
end | ||
end | ||
@testset "Torus" begin | ||
for r_tube in (2.0, Dict("from" => 1.0, "to" => 2.0)), | ||
φmax in (180,360), | ||
θmin in 0:45:90, | ||
θmax in 135:45:270 | ||
|
||
dict = Dict("difference" => [ | ||
Dict( "torus" => Dict( | ||
"r_torus" => 10.0, | ||
"r_tube" => r_tube, | ||
"phi" => Dict("from" => "0°", "to" => "$(φmax)°"), | ||
"theta" => Dict("from" => "$(θmin)°", "to" => "$(θmax)°"))) | ||
for i in 1:2 | ||
]) | ||
t = Geometry(T, dict, default_units, no_translations) | ||
|
||
# No warnings or errors when decomposing the Torus into surfaces | ||
@test_nowarn CSG.surfaces(t.a) | ||
@test_nowarn CSG.surfaces(t.b) | ||
|
||
# Check that the r field for all ConeMantles is ordered | ||
for surf in CSG.surfaces(t.a) surf isa CSG.ConeMantle && @test_skip surf.r[1] <= surf.r[2] end | ||
|
||
# Check if all Torus are saved the right way | ||
@test t.a isa CSG.Torus | ||
@test t.b isa CSG.Torus | ||
end | ||
end | ||
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