Skip to content

Commit f9d4103

Browse files
Expand tests
1 parent d249404 commit f9d4103

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

test/reduce.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,25 +146,29 @@ end
146146
@test vvminimum([0.,-0.]) === -0.0
147147
@test vvminimum([0.,-0.,0.]) === -0.0
148148

149-
@testset "minimum/maximum checks all elements" begin
149+
@testset "minimum/maximum/extrema checks all elements" begin
150150
for N in [2:20;150;300]
151151
for i in 1:N
152152
arr = fill(0., N)
153153
truth = rand()
154154
arr[i] = truth
155155
@test vvmaximum(arr) == truth
156+
@test vvextrema(arr) == (0., truth)
156157

157158
truth = -rand()
158159
arr[i] = truth
159160
@test vvminimum(arr) == truth
161+
@test vvextrema(arr) == (truth, 0.)
160162

161163
arr[i] = NaN
162164
@test !isnan(vvmaximum(arr)) # NaN not handled
163165
@test !isnan(vvminimum(arr)) # NaN not handled
166+
@test all(!isnan, vvextrema(arr))
164167

165168
arr = zeros(N)
166169
@test vvminimum(arr) === 0.0
167170
@test vvmaximum(arr) === 0.0
171+
@test vvextrema(arr) === (0.0, 0.0)
168172

169173
# arr[i] = -0.0
170174
# @test vvminimum(arr) === 0.0 # opposite from base
@@ -173,6 +177,7 @@ end
173177
arr = -zeros(N)
174178
@test vvminimum(arr) === -0.0
175179
@test vvmaximum(arr) === -0.0
180+
@test vvextrema(arr) === (-0.0, -0.0)
176181
# arr[i] = 0.0
177182
# @test vvminimum(arr) === -0.0
178183
# @test vvmaximum(arr) === -0.0 # opposite from base
@@ -183,15 +188,18 @@ end
183188
@testset "maximum no out of bounds access #30462" begin
184189
arr = fill(-Inf, 128,128)
185190
@test vvmaximum(arr) == -Inf
191+
@test vvextrema(arr) == (-Inf, -Inf)
186192
arr = fill(Inf, 128^2)
187193
@test vvminimum(arr) == Inf
194+
@test vvextrema(arr) == (Inf, Inf)
188195
for center in [256, 1024, 4096, 128^2]
189196
for offset in -10:10
190197
len = center + offset
191198
x = randn()
192199
arr = fill(x, len)
193200
@test vvmaximum(arr) === x
194201
@test vvminimum(arr) === x
202+
@test vvextrema(arr) === (x, x)
195203
end
196204
end
197205
end

test/reducedim.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
@testset "test reductions over region: $region" for region in Any[
55
1, 2, 3, 4, 5, (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4),
6-
(1, 2, 3), (1, 3, 4), (2, 3, 4), (1, 2, 3, 4)]
6+
(1, 2, 3), (1, 3, 4), (2, 3, 4), (1, 2, 3, 4), :]
77
A = rand(3, 4, 5, 6)
88

99
@test sum(A, dims=region) vvsum(A, dims=region)

test/treduce.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,25 +146,29 @@ end
146146
@test vtminimum([0.,-0.]) === -0.0
147147
@test vtminimum([0.,-0.,0.]) === -0.0
148148

149-
@testset "minimum/maximum checks all elements" begin
149+
@testset "minimum/maximum/extrema checks all elements" begin
150150
for N in [2:20;150;300]
151151
for i in 1:N
152152
arr = fill(0., N)
153153
truth = rand()
154154
arr[i] = truth
155155
@test vtmaximum(arr) == truth
156+
@test vtextrema(arr) == (0., truth)
156157

157158
truth = -rand()
158159
arr[i] = truth
159160
@test vtminimum(arr) == truth
161+
@test vtextrema(arr) == (truth, 0.)
160162

161163
arr[i] = NaN
162164
@test !isnan(vtmaximum(arr)) # NaN not handled
163165
@test !isnan(vtminimum(arr)) # NaN not handled
166+
@test all(!isnan, vtextrema(arr))
164167

165168
arr = zeros(N)
166169
@test vtminimum(arr) === 0.0
167170
@test vtmaximum(arr) === 0.0
171+
@test vtextrema(arr) === (0.0, 0.0)
168172

169173
# arr[i] = -0.0
170174
# @test vtminimum(arr) === 0.0 # opposite from base
@@ -173,6 +177,7 @@ end
173177
arr = -zeros(N)
174178
@test vtminimum(arr) === -0.0
175179
@test vtmaximum(arr) === -0.0
180+
@test vvextrema(arr) === (-0.0, -0.0)
176181
# arr[i] = 0.0
177182
# @test vtminimum(arr) === -0.0
178183
# @test vtmaximum(arr) === -0.0 # opposite from base
@@ -183,15 +188,18 @@ end
183188
@testset "maximum no out of bounds access #30462" begin
184189
arr = fill(-Inf, 128,128)
185190
@test vtmaximum(arr) == -Inf
191+
@test vtextrema(arr) == (-Inf, -Inf)
186192
arr = fill(Inf, 128^2)
187193
@test vtminimum(arr) == Inf
194+
@test vtextrema(arr) == (Inf, Inf)
188195
for center in [256, 1024, 4096, 128^2]
189196
for offset in -10:10
190197
len = center + offset
191198
x = randn()
192199
arr = fill(x, len)
193200
@test vtmaximum(arr) === x
194201
@test vtminimum(arr) === x
202+
@test vtextrema(arr) === (x, x)
195203
end
196204
end
197205
end

test/treducedim.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
@testset "threaded test reductions over region: $region" for region in Any[
55
1, 2, 3, 4, 5, (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4),
6-
(1, 2, 3), (1, 3, 4), (2, 3, 4), (1, 2, 3, 4)]
6+
(1, 2, 3), (1, 3, 4), (2, 3, 4), (1, 2, 3, 4), :]
77
A = rand(3, 4, 5, 6)
88

99
@test sum(A, dims=region) vtsum(A, dims=region)

0 commit comments

Comments
 (0)