Skip to content

Commit 1c3a371

Browse files
committed
outline SVHN2 tests
1 parent ca09717 commit 1c3a371

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

src/SVHN2/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ function convert2features(array::AbstractArray{<:Number,4})
2929
end
3030

3131
convert2features(array::AbstractArray{<:RGB,2}) =
32-
convert2features(permutedims(channelview(array), (3,1,2)))
32+
convert2features(permutedims(channelview(array), (2,3,1)))
3333

3434
convert2features(array::AbstractArray{<:RGB,3}) =
35-
convert2features(permutedims(channelview(array), (3,1,2,4)))
35+
convert2features(permutedims(channelview(array), (2,3,1,4)))
3636

3737
"""
3838
convert2image(array) -> Array{RGB}

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ tests = [
66
"tst_cifar100.jl",
77
"tst_mnist.jl",
88
"tst_fashion_mnist.jl",
9+
"tst_svhn2.jl",
910
]
1011

1112
for t in tests

test/tst_svhn2.jl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
module SVHN2_Tests
2+
using Base.Test
3+
using ColorTypes
4+
using ImageCore
5+
using FixedPointNumbers
6+
using MLDatasets
7+
using DataDeps
8+
9+
@testset "Constants" begin
10+
@test SVHN2.classnames() isa Vector{Int}
11+
@test SVHN2.classnames() == [1,2,3,4,5,6,7,8,9,0]
12+
@test length(SVHN2.classnames()) == 10
13+
@test length(unique(SVHN2.classnames())) == 10
14+
15+
@test DataDeps.registry["SVHN2"] isa DataDeps.DataDep
16+
end
17+
18+
@testset "convert2features" begin
19+
data = rand(32,32,3)
20+
ref = vec(data)
21+
@test @inferred(SVHN2.convert2features(data)) == ref
22+
@test @inferred(SVHN2.convert2features(SVHN2.convert2image(data))) == ref
23+
24+
data = rand(32,32,3,2)
25+
ref = reshape(data, (32*32*3, 2))
26+
@test @inferred(SVHN2.convert2features(data)) == ref
27+
@test @inferred(SVHN2.convert2features(SVHN2.convert2image(data))) == ref
28+
end
29+
30+
@testset "convert2images" begin
31+
@test_throws AssertionError SVHN2.convert2image(rand(100))
32+
@test_throws AssertionError SVHN2.convert2image(rand(228,1))
33+
@test_throws AssertionError SVHN2.convert2image(rand(32,32,4))
34+
35+
data = rand(N0f8,32,32,3)
36+
A = @inferred SVHN2.convert2image(data)
37+
@test size(A) == (32,32)
38+
@test eltype(A) == RGB{N0f8}
39+
@test SVHN2.convert2image(vec(data)) == A
40+
@test permutedims(channelview(A), (2,3,1)) == data
41+
@test SVHN2.convert2image(reinterpret(UInt8, data)) == A
42+
43+
data = rand(N0f8,32,32,3,2)
44+
A = @inferred SVHN2.convert2image(data)
45+
@test size(A) == (32,32,2)
46+
@test eltype(A) == RGB{N0f8}
47+
@test SVHN2.convert2image(vec(data)) == A
48+
@test SVHN2.convert2image(SVHN2.convert2features(data)) == A
49+
@test SVHN2.convert2image(reinterpret(UInt8, data)) == A
50+
end
51+
52+
# NOT executed on CI. only executed locally.
53+
# This involves dataset download etc.
54+
if parse(Bool, get(ENV, "CI", "false"))
55+
info("CI detected: skipping dataset download")
56+
else
57+
data_dir = withenv("DATADEPS_ALWAY_ACCEPT"=>"true") do
58+
datadep"SVHN2"
59+
end
60+
end
61+
62+
end

0 commit comments

Comments
 (0)