Skip to content

Commit 5cfd12f

Browse files
committed
add tests for utility functions
1 parent d3be353 commit 5cfd12f

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

test/core-test/utilities.jl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@testset "Utilities" verbose = true begin
2+
@testset "n_thermal" begin
3+
ω1 = rand(Float64)
4+
ω2 = rand(Float64)
5+
@test n_thermal(0, ω2) == 0.0
6+
@test n_thermal(ω1, 0) == 0.0
7+
@test n_thermal(ω1, -ω2) == 0.0
8+
@test n_thermal(ω1, ω2) == 1 / (exp(ω1 / ω2) - 1)
9+
@test typeof(n_thermal(Int32(2), Int32(3))) == Float32
10+
@test typeof(n_thermal(Float32(2), Float32(3))) == Float32
11+
@test typeof(n_thermal(Int64(2), Int32(3))) == Float64
12+
@test typeof(n_thermal(Int32(2), Int64(3))) == Float64
13+
@test typeof(n_thermal(Float64(2), Float32(3))) == Float64
14+
@test typeof(n_thermal(Float32(2), Float64(3))) == Float64
15+
end
16+
17+
@testset "convert unit" begin
18+
V = 100 * rand(Float64)
19+
_unit_list = [:J, :eV, :meV, :GHz, :mK]
20+
for origin in _unit_list
21+
for middle in _unit_list
22+
for target in _unit_list
23+
V_middle = convert_unit(V, origin, middle)
24+
V_target = convert_unit(V_middle, middle, target)
25+
V_origin = convert_unit(V_target, target, origin)
26+
@test V V_origin
27+
end
28+
end
29+
end
30+
@test_throws ArgumentError convert_unit(V, :bad_unit, :J)
31+
@test_throws ArgumentError convert_unit(V, :J, :bad_unit)
32+
end
33+
34+
@testset "Type Inference" begin
35+
v1 = rand(Float64)
36+
@inferred n_thermal(v1, Int32(123))
37+
38+
_unit_list = [:J, :eV, :meV, :GHz, :mK]
39+
for u1 in _unit_list
40+
for u2 in _unit_list
41+
@inferred convert_unit(v1, u1, u2)
42+
end
43+
end
44+
end
45+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ core_tests = [
2323
"states_and_operators.jl",
2424
"steady_state.jl",
2525
"time_evolution.jl",
26+
"utilities.jl",
2627
"wigner.jl",
2728
]
2829

0 commit comments

Comments
 (0)