Skip to content

Commit

Permalink
Merge pull request #394 from timholy/teh/testing_fixes
Browse files Browse the repository at this point in the history
Testing fixes
  • Loading branch information
timholy committed Nov 3, 2015
2 parents d960a1c + 531e3ce commit 814a3d6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,18 @@ similar{T,F,To,From,S}(mapi::ScaleMinMax{To,From,S}, ::Type{T}, ::Type{F}) = Sca
# Implementation
function map{To<:Union{Real,AbstractGray},From<:Union{Real,AbstractGray}}(mapi::ScaleMinMax{To,From}, val::From)
g = gray(val)
t = ifelse(g < mapi.min, zero(From), ifelse(g > mapi.max, mapi.max-mapi.min, g-mapi.min))
t = ifelse(g < mapi.min, zero(From), ifelse(g > mapi.max, mapi.max-mapi.min, g-mapi.min))
convert(To, mapi.s*t)
end
function map{To<:Union{Real,AbstractGray},From<:Union{Real,AbstractGray}}(mapi::ScaleMinMax{To,From}, val::Union{Real,Colorant})
map(mapi, convert(From, val))
end
function map1{To<:Union{RGB24,ARGB32},From<:Real}(mapi::ScaleMinMax{To,From}, val::From)
t = ifelse(val < mapi.min, zero(From), ifelse(val > mapi.max, mapi.max-mapi.min, val -mapi.min))
t = ifelse(val < mapi.min, zero(From), ifelse(val > mapi.max, mapi.max-mapi.min, val-mapi.min))
convert(UFixed8, mapi.s*t)
end
function map1{To<:Colorant,From<:Real}(mapi::ScaleMinMax{To,From}, val::From)
t = ifelse(val < mapi.min, zero(From), ifelse(val > mapi.max, mapi.max-mapi.min, val -mapi.min))
t = ifelse(val < mapi.min, zero(From), ifelse(val > mapi.max, mapi.max-mapi.min, val-mapi.min))
convert(eltype(To), mapi.s*t)
end
function map1{To<:Union{RGB24,ARGB32},From<:Real}(mapi::ScaleMinMax{To,From}, val::Union{Real,Colorant})
Expand Down
14 changes: 7 additions & 7 deletions test/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ facts("Algorithms") do
@fact Images.sad(ag, bg) --> roughly(387f0/255)
@fact Images.ssd(ag, bg) --> roughly(80699f0/255^2)

a = rand(5,5)
@fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a rand(3,5) [1,1] 0.1)
@fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a rand(5,5) [1,1] 0.1)
@fact (Images.@test_approx_eq_sigma_eps a a [1,1] 0.1) --> nothing
a = rand(15,15)
@fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a rand(13,15) [1,1] 0.01)
@fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a rand(15,15) [1,1] 0.01)
@fact (Images.@test_approx_eq_sigma_eps a a [1,1] 0.01) --> nothing
@fact (Images.@test_approx_eq_sigma_eps a a+0.01*rand(size(a)) [1,1] 0.1) --> nothing
@fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a a+0.5*rand(size(a)) [1,1] 0.1)
a = colorim(rand(3,5,5))
@fact (Images.@test_approx_eq_sigma_eps a a [1,1] 0.1) --> nothing
@fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a colorim(rand(3,5,5)) [1,1] 0.1)
a = colorim(rand(3,15,15))
@fact (Images.@test_approx_eq_sigma_eps a a [1,1] 0.01) --> nothing
@fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a colorim(rand(3,15,15)) [1,1] 0.01)
end

context("fft and ifft") do
Expand Down
4 changes: 2 additions & 2 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ facts("Core") do
@fact imgc.data --> img.data
imgc = copyproperties(imgd, A)
@fact imgc.data --> A
img2 = similar(img)
img2 = @inferred(similar(img))
@fact isa(img2, ImageCmap) --> true
@fact (img2.data == img.data) --> false
img2 = similar(imgd)
img2 = @inferred(similar(imgd))
@fact isa(img2, Image) --> true
img2 = similar(img, (4,4))
@fact isa(img2, ImageCmap) --> true
Expand Down
10 changes: 6 additions & 4 deletions test/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,12 @@ facts("Map") do
res1 = raw(map(mi1, imgr))
mi2 = ScaleAutoMinMax(UFixed16)
res2 = raw(map(mi2, raw(imgr)))
if res1 != res2
@show A
end
@fact res1 --> res2
# @fact res1 --> res2
# Note: this fails occassionally. Reproduce it with
# s = 1.1269798f0
# val = 0xdeb5
# UFixed16(s*UFixed16(val,0)) == UFixed16((s/typemax(UInt16))*val)
@fact maxabs(convert(Array{Int32}, res1) - convert(Array{Int32}, res2)) --> less_than_or_equal(1)
end

context("Scaling and ssd") do
Expand Down

0 comments on commit 814a3d6

Please sign in to comment.