1+
2+ using FunctionMaps:
3+ hashrec,
4+ convert_numtype,
5+ promote_numtype,
6+ to_numtype,
7+ convert_prectype,
8+ promote_prectype,
9+ to_prectype,
10+ convert_eltype,
11+ euclideandimension,
12+ isrealtype
13+
14+ function test_hashrec ()
15+ @test hashrec () == 0
16+ @test hashrec () isa UInt
17+ A = [1 ,2 ]
18+ @test hashrec (A) == hash (2 , hash (1 , hash ((2 ,))))
19+ @test hashrec (1 , 2 ) == hash (1 , hash (2 ))
20+ end
21+
122function test_dimension ()
223 @test euclideandimension (Int) == 1
324 @test euclideandimension (Float64) == 1
@@ -10,6 +31,7 @@ function test_dimension()
1031end
1132
1233function test_prectype ()
34+ @test prectype (:some_symbol ) == Any
1335 @test prectype (1.0 ) == Float64
1436 @test prectype (big (1.0 )) == BigFloat
1537 @test prectype (1 ) == typeof (float (1 ))
@@ -44,10 +66,26 @@ function test_prectype()
4466 @test promote_prectype (2 ) == 2
4567 @test promote_prectype (2 , 3.0 ) isa Tuple{Float64,Float64}
4668 @test promote_prectype (2 , 3.0 + im, big (4 )) isa Tuple{BigFloat,Complex{BigFloat},BigFloat}
69+
70+ @test to_prectype (Float64, Int) === Float64
71+ @test to_prectype (Float32, Float64) === Float32
72+ @test to_prectype (Int, Int) === Int
73+
74+ @test to_prectype (Float64, Complex{Int}) === Complex{Float64}
75+ @test to_prectype (Float32, Complex{Float64}) === Complex{Float32}
76+ @test to_prectype (Float64, Vector{Int}) === Vector{Float64}
77+ @test to_prectype (Float32, Vector{Float64}) === Vector{Float32}
78+ @test to_prectype (Float64, SVector{3 ,Int}) === SVector{3 ,Float64}
79+ @test to_prectype (Float32, MVector{3 ,Float64}) === MVector{3 ,Float32}
80+ @test to_prectype (Float64, SMatrix{2 ,2 ,Int}) === SMatrix{2 ,2 ,Float64}
81+ @test to_prectype (Float32, MMatrix{2 ,2 ,Float64}) === MMatrix{2 ,2 ,Float32}
82+ @test_throws ArgumentError to_prectype (Float64, String)
83+ @test_throws ArgumentError to_prectype (Float64, Dict{Int,Float64})
4784end
4885
4986
5087function test_numtype ()
88+ @test numtype (:some_symbol ) == Any
5189 @test numtype (1.0 ) == Float64
5290 @test numtype (big (1.0 )) == BigFloat
5391 @test numtype (1 ) == Int
@@ -64,6 +102,7 @@ function test_numtype()
64102 @test numtype ((1.0 , 2.0 , 3.0 , 4.0 )) == Float64
65103 @test numtype (1.0 , big (2.0 ), 3.0 + im) == Complex{BigFloat}
66104 @test numtype (typeof ((1.0 , big (2.0 ), 3.0 + im))) == Complex{BigFloat}
105+ @test numtype (Tuple{Int,Int,Int,Int,Float64}) == Float64
67106 @test @inferred (numtype (1 , 2.0 )) == Float64
68107 @test @inferred (numtype (typeof ((1 , 2.0 , 3 , 40 + im)))) == Complex{Float64}
69108
@@ -82,9 +121,34 @@ function test_numtype()
82121 @test promote_numtype (2 ) == 2
83122 @test promote_numtype (2 , 3.0 ) isa Tuple{Float64,Float64}
84123 @test promote_numtype (2 , 3.0 + im, big (4 )) isa Tuple{Complex{BigFloat},Complex{BigFloat},Complex{BigFloat}}
124+
125+ @test to_numtype (Float64, Int) === Float64
126+ @test to_numtype (Float32, Float64) === Float32
127+ @test to_numtype (Int, Int) === Int
128+
129+ @test to_numtype (Float64, Vector{Int}) === Vector{Float64}
130+ @test to_numtype (Float32, Vector{Float64}) === Vector{Float32}
131+ @test to_numtype (Float64, SVector{3 ,Int}) === SVector{3 ,Float64}
132+ @test to_numtype (Float32, MVector{3 ,Float64}) === MVector{3 ,Float32}
133+ @test to_numtype (Float64, SMatrix{2 ,2 ,Int}) === SMatrix{2 ,2 ,Float64}
134+ @test to_numtype (Float32, MMatrix{2 ,2 ,Float64}) === MMatrix{2 ,2 ,Float32}
135+ @test_throws ArgumentError to_numtype (Float64, String)
136+ @test_throws ArgumentError to_numtype (Float64, Dict{Int,Float64})
85137end
86138
87- using FunctionMaps: isrealtype
139+ function test_eltype ()
140+ @test convert_eltype (Float64, Diagonal ([1 ,2 ])) == Diagonal ([1 ,2 ])
141+ @test eltype (convert_eltype (Float64, Diagonal ([1 ,2 ]))) == Float64
142+ @test convert_eltype (Float64, 1 : 4 ) == 1 : 4
143+ @test eltype (convert_eltype (Float64, 1 : 4 )) == Float64
144+ @test convert_eltype (Float64, Set ([1 ,4 ])) == Set ([1 ,4 ])
145+ @test eltype (convert_eltype (Float64, Set ([1 ,4 ]))) == Float64
146+ @test convert_eltype (Float64, 5 ) == 5
147+ @test eltype (convert_eltype (Float64, 5 )) == Float64
148+
149+ @test FunctionMaps. promotable_eltypes (Int,Float64)
150+ @test FunctionMaps. promotable_eltypes (Vector{Int},Vector{Float64})
151+ end
88152
89153function test_realtype ()
90154 @test isrealtype (Any) == false
@@ -94,15 +158,10 @@ function test_realtype()
94158end
95159
96160@testset " common functionality" begin
97- @testset " dimension" begin
98- test_dimension ()
99- end
100- @testset " prectype" begin
101- test_prectype ()
102- end
103- @testset " numtype" begin
104- test_numtype ()
105- end
106-
161+ test_hashrec ()
162+ test_dimension ()
163+ test_prectype ()
164+ test_numtype ()
165+ test_eltype ()
107166 test_realtype ()
108167end
0 commit comments