-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* introduce `convert_unit` * add tests for utility functions * fix value of physical constants
- Loading branch information
Showing
4 changed files
with
92 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
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,45 @@ | ||
@testset "Utilities" verbose = true begin | ||
@testset "n_thermal" begin | ||
ω1 = rand(Float64) | ||
ω2 = rand(Float64) | ||
@test n_thermal(0, ω2) == 0.0 | ||
@test n_thermal(ω1, 0) == 0.0 | ||
@test n_thermal(ω1, -ω2) == 0.0 | ||
@test n_thermal(ω1, ω2) == 1 / (exp(ω1 / ω2) - 1) | ||
@test typeof(n_thermal(Int32(2), Int32(3))) == Float32 | ||
@test typeof(n_thermal(Float32(2), Float32(3))) == Float32 | ||
@test typeof(n_thermal(Int64(2), Int32(3))) == Float64 | ||
@test typeof(n_thermal(Int32(2), Int64(3))) == Float64 | ||
@test typeof(n_thermal(Float64(2), Float32(3))) == Float64 | ||
@test typeof(n_thermal(Float32(2), Float64(3))) == Float64 | ||
end | ||
|
||
@testset "convert unit" begin | ||
V = 100 * rand(Float64) | ||
_unit_list = [:J, :eV, :meV, :GHz, :mK] | ||
for origin in _unit_list | ||
for middle in _unit_list | ||
for target in _unit_list | ||
V_middle = convert_unit(V, origin, middle) | ||
V_target = convert_unit(V_middle, middle, target) | ||
V_origin = convert_unit(V_target, target, origin) | ||
@test V ≈ V_origin | ||
end | ||
end | ||
end | ||
@test_throws ArgumentError convert_unit(V, :bad_unit, :J) | ||
@test_throws ArgumentError convert_unit(V, :J, :bad_unit) | ||
end | ||
|
||
@testset "Type Inference" begin | ||
v1 = rand(Float64) | ||
@inferred n_thermal(v1, Int32(123)) | ||
|
||
_unit_list = [:J, :eV, :meV, :GHz, :mK] | ||
for u1 in _unit_list | ||
for u2 in _unit_list | ||
@inferred convert_unit(v1, u1, u2) | ||
end | ||
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