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
+
1
22
function test_dimension ()
2
23
@test euclideandimension (Int) == 1
3
24
@test euclideandimension (Float64) == 1
@@ -10,6 +31,7 @@ function test_dimension()
10
31
end
11
32
12
33
function test_prectype ()
34
+ @test prectype (:some_symbol ) == Any
13
35
@test prectype (1.0 ) == Float64
14
36
@test prectype (big (1.0 )) == BigFloat
15
37
@test prectype (1 ) == typeof (float (1 ))
@@ -44,10 +66,26 @@ function test_prectype()
44
66
@test promote_prectype (2 ) == 2
45
67
@test promote_prectype (2 , 3.0 ) isa Tuple{Float64,Float64}
46
68
@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})
47
84
end
48
85
49
86
50
87
function test_numtype ()
88
+ @test numtype (:some_symbol ) == Any
51
89
@test numtype (1.0 ) == Float64
52
90
@test numtype (big (1.0 )) == BigFloat
53
91
@test numtype (1 ) == Int
@@ -64,6 +102,7 @@ function test_numtype()
64
102
@test numtype ((1.0 , 2.0 , 3.0 , 4.0 )) == Float64
65
103
@test numtype (1.0 , big (2.0 ), 3.0 + im) == Complex{BigFloat}
66
104
@test numtype (typeof ((1.0 , big (2.0 ), 3.0 + im))) == Complex{BigFloat}
105
+ @test numtype (Tuple{Int,Int,Int,Int,Float64}) == Float64
67
106
@test @inferred (numtype (1 , 2.0 )) == Float64
68
107
@test @inferred (numtype (typeof ((1 , 2.0 , 3 , 40 + im)))) == Complex{Float64}
69
108
@@ -82,9 +121,34 @@ function test_numtype()
82
121
@test promote_numtype (2 ) == 2
83
122
@test promote_numtype (2 , 3.0 ) isa Tuple{Float64,Float64}
84
123
@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})
85
137
end
86
138
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
88
152
89
153
function test_realtype ()
90
154
@test isrealtype (Any) == false
@@ -94,15 +158,10 @@ function test_realtype()
94
158
end
95
159
96
160
@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 ()
107
166
test_realtype ()
108
167
end
0 commit comments