From 22401af749fda44b2e724a3ea5741518d97a32d0 Mon Sep 17 00:00:00 2001 From: Alex Riss <00alexx@riss.at> Date: Tue, 2 Jan 2024 16:42:34 +0100 Subject: [PATCH] add tests for fadeout --- test/runtests.jl | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 125dcd4..ce22292 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -121,4 +121,42 @@ end close(ChemfilesViewer.get_reference(viewer_id)[1]) @test filesize("test.png") > 10000 + + img = rand(RGBA, 10, 10) + faded_img = fadeout_img(img, 0.08) + @test size(faded_img) == size(img) + for c in (:r, :g, :b) + @test getfield.(faded_img, c) == getfield.(img, c) + end + @test all(getfield.(faded_img, :alpha) .<= getfield.(img, :alpha)) + + img = load("test.png") + faded_img = fadeout_img("test.png", 0.15) + for c in (:r, :g, :b) + @test getfield.(faded_img, c) == getfield.(img, c) + end + @test all(getfield.(faded_img, :alpha) .<= getfield.(img, :alpha)) + + img = fill(RGBA(0.2, 0.4, 0.5), 100, 100) + faded_img = fadeout_img(img, 0.15) + @test size(faded_img) == size(img) + for c in (:r, :g, :b) + @test getfield.(faded_img, c) == getfield.(img, c) + end + @test all(getfield.(faded_img, :alpha) .<= getfield.(img, :alpha)) + + @test all(getfield.(faded_img[1,:], :alpha) .== 0.0) + @test all(getfield.(faded_img[:,1], :alpha) .== 0.0) + @test all(getfield.(faded_img[end,:], :alpha) .== 0.0) + @test all(getfield.(faded_img[:,end], :alpha) .== 0.0) + + @test all(getfield.(faded_img[2,:], :alpha) .< 0.1) + @test all(getfield.(faded_img[:,2], :alpha) .< 0.1) + @test all(getfield.(faded_img[end-1,:], :alpha) .< 0.1) + @test all(getfield.(faded_img[:,end-1], :alpha) .< 0.1) + + @test all(getfield.(faded_img[15:85,15:85], :alpha) .== 1.0) + @test all(getfield.(faded_img[1:14,:], :alpha) .< 1.0) + @test all(getfield.(faded_img[86:end,:], :alpha) .< 1.0) + @test all(getfield.(faded_img[:,86:end], :alpha) .< 1.0) end