Skip to content

Commit 65475bf

Browse files
committed
Refactor unittests
1 parent fcca5ac commit 65475bf

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

test/unittests.jl

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1-
using Test: @test, @inferred
1+
using Test: @test, @testset, @inferred
22
using BaseType: base_numeric_type
33
using DualNumbers: DualNumbers
44
using DynamicQuantities: DynamicQuantities
55
using Measurements: ±
66
using Unitful: Unitful
77

8-
expected_type_pairs = [
9-
Float32 => Float32,
10-
ComplexF64 => Float64,
11-
DualNumbers.Dual{Int64} => Int64,
12-
DynamicQuantities.Quantity{Float32} => Float32,
13-
typeof(1.5DynamicQuantities.u"km/s") => Float64,
14-
typeof(1.5f0Unitful.u"km/s") => Float32,
15-
BigFloat => BigFloat,
16-
typeof(1.5 ± 0.2) => Float64,
17-
typeof(1.5f0 ± 0.2f0) => Float32,
18-
]
8+
@testset "Basic usage" begin
9+
expected_type_pairs = [
10+
Float32 => Float32,
11+
ComplexF64 => Float64,
12+
DualNumbers.Dual{Int64} => Int64,
13+
DynamicQuantities.Quantity{Float32} => Float32,
14+
typeof(1.5DynamicQuantities.u"km/s") => Float64,
15+
typeof(1.5f0Unitful.u"km/s") => Float32,
16+
BigFloat => BigFloat,
17+
typeof(1.5 ± 0.2) => Float64,
18+
typeof(1.5f0 ± 0.2f0) => Float32,
19+
]
1920

20-
for (x, y) in expected_type_pairs
21-
@eval @test base_numeric_type($x) == $y
22-
# Make sure compiler can inline it:
23-
@eval @inferred $y base_numeric_type($x)
21+
for (x, y) in expected_type_pairs
22+
@eval @test base_numeric_type($x) == $y
23+
# Make sure compiler can inline it:
24+
@eval @inferred $y base_numeric_type($x)
25+
end
26+
27+
@test base_numeric_type(1.5DynamicQuantities.u"km/s") == base_numeric_type(typeof(1.5DynamicQuantities.u"km/s"))
28+
@inferred base_numeric_type(1.5DynamicQuantities.u"km/s")
2429
end
2530

2631
@test base_numeric_type(1.5DynamicQuantities.u"km/s") == base_numeric_type(typeof(1.5DynamicQuantities.u"km/s"))

0 commit comments

Comments
 (0)