Skip to content

Commit cf57562

Browse files
authored
Add more tests of mean and median of ranges
1 parent 128dc11 commit cf57562

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/runtests.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,30 @@ end
218218
@test mean(prevfloat(Inf):prevfloat(Inf)) === prevfloat(Inf)
219219
end
220220

221+
@testset "means (etc) of ranges; issue #120" begin
222+
@test (@inferred mean(Int8(123):Int8(123))) === 123.0
223+
@test (@inferred median(Int8(123):Int8(123))) === 123.0
224+
@test (@inferred mean(Int8(126):Int8(127))) === 126.5
225+
@test (@inferred median(Int8(126):Int8(127))) === 126.5
226+
@test (@inferred mean(typemax(Int):typemax(Int))) === typemax(Int)/1
227+
@test (@inferred median(typemax(Int):typemax(Int))) === typemax(Int)/1
228+
@test (@inferred mean(UInt8(255):UInt8(255))) === 255.0
229+
@test (@inferred median(UInt8(255):UInt8(255))) === 255.0
230+
@test (@inferred mean(Float16(12345):Float16(12345))) === Float16(12345)
231+
@test (@inferred median(Float16(12345):Float16(12345))) === Float16(12345)
232+
@test (@inferred mean(Float16(12345):Float16(54321))) === Float16(33333)
233+
@test (@inferred median(Float16(12345):Float16(54321))) === Float16(33333)
234+
235+
for T in (Int8, UInt8, Int32, UInt32, Int64, UInt64)
236+
@test (@inferred mean(typemin(T):typemin(T))) === typemin(T)/1
237+
@test (@inferred median(typemin(T):typemin(T))) === typemin(T)/1
238+
@test (@inferred mean(typemax(T):typemax(T))) === typemax(T)/1
239+
@test (@inferred median(typemax(T):typemax(T))) === typemax(T)/1
240+
@test (@inferred mean(typemin(T):typemin(T))) === typemin(T)/1
241+
@test (@inferred median(typemin(T):typemin(T))) === typemin(T)/1
242+
end
243+
end
244+
221245
@testset "var & std" begin
222246
# edge case: empty vector
223247
# iterable; this has to throw for type stability

0 commit comments

Comments
 (0)