|
| 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