Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Aug 30, 2022
1 parent 2f17c2d commit 6745909
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions test/backend/libsixel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
@testset "1d vector" begin
for img in (
repeat(Gray.(0:0.1:0.9), inner=10),
repeat(distinguishable_colors(10), inner=(10, ))
repeat(distinguishable_colors(10), inner=(10,)),
repeat(alphacolor.(distinguishable_colors(10), 0.5), inner=(10,))
)
@info "1d vector: $(eltype(img))"
@test size(img) == (100, )
Expand Down Expand Up @@ -59,7 +60,8 @@
@testset "2d matrix" begin
for img in (
repeat(Gray.(0:0.1:0.9), inner=(10, 50)),
repeat(distinguishable_colors(10), inner=(10, 50))
repeat(distinguishable_colors(10), inner=(10, 50)),
repeat(coloralpha.(distinguishable_colors(10), 0.5), inner=(10, 50)),
)
@info "2d matrix: $(eltype(img))"
h, w = size(img)
Expand Down Expand Up @@ -101,7 +103,8 @@
@testset "3d array" begin
for img in (
repeat(Gray.(0:0.1:0.9), inner=(10, 50, 3)),
repeat(distinguishable_colors(5), inner=(20, 50, 3))
repeat(distinguishable_colors(5), inner=(20, 50, 3)),
repeat(alphacolor.(distinguishable_colors(5), 0.5), inner=(20, 50, 3)),
)
@info "3d array: $(eltype(img))"
@test size(img) == (100, 50, 3)
Expand Down Expand Up @@ -217,11 +220,11 @@

@testset "OffsetArray" begin
enc = Sixel.LibSixelEncoder()
for img in [
for img in (
repeat(distinguishable_colors(10), inner=(10, )),
repeat(distinguishable_colors(10), inner=(10, 50)),
repeat(distinguishable_colors(5), inner=(20, 50, 3))
]
)
io = IOBuffer()
sixel_encode(io, img, enc)
ref = String(take!(io))
Expand Down Expand Up @@ -292,23 +295,29 @@ end
dec = Sixel.LibSixelDecoder()
tmp_file = tempname()

alpha_channel = range(0, 1, length=10)
for img in (
repeat(Gray.(0:0.1:0.9), inner=10),
repeat(distinguishable_colors(10), inner=(10, )),
repeat(distinguishable_colors(10), inner=(10,)),
repeat(alphacolor.(distinguishable_colors(10), alpha_channel), inner=(10,)), # add linear alpha channel
repeat(Gray.(0:0.1:0.9), inner=(10, 50)),
repeat(distinguishable_colors(10), inner=(10, 50)),
repeat(Gray.(0:0.1:0.9), inner=(10, 50, 3)),
repeat(distinguishable_colors(5), inner=(20, 50, 3))
repeat(distinguishable_colors(5), inner=(20, 50, 3)),
)
open(tmp_file, "w") do io
sixel_encode(io, img, enc)
end

img_readback = open(tmp_file, "r") do io
sixel_decode(eltype(img), io, dec)
end |> x -> reshape(x, size(img))

if eltype(img) <: TransparentColor
@test isapprox.(alpha.(img), repeat(alpha_channel, inner=(10,)), atol=1e-2) |> all
img, img_readback = color.(img), color.(img_readback)
end

img_readback = reshape(img_readback, size(img))
# 30 is actually pretty good given that sixel encode always do quantization
@test assess_psnr(img, img_readback) > 30
end
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using LinearAlgebra
using FileIO, TestImages

sixel_output = Sixel.is_sixel_supported()
sixel_output || @info "Current terminal does not support sixel format sequence. Display tests to stdout will be marked as broken."
sixel_output || @info "Current terminal does not support sixel format sequence (or querying failed as is the case with non-interactive mode). Display tests to stdout will be marked as broken."
function test_sixel_display(f)
if sixel_output
@test_nowarn f()
Expand Down

0 comments on commit 6745909

Please sign in to comment.