Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Jul 29, 2023
1 parent de5e6ef commit 4ad7265
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,66 @@ end
pl[1] = [points]
@test pl.plots[1][1][] == Makie.poly_convert(points)
end


@testset "GridBased and ImageLike conversions" begin
# type tree
@test GridBased <: ConversionTrait
@test CellBasedGrid <: GridBased
@test VertexBasedGrid <: GridBased
@test ImageLike <: ConversionTrait

# Plot to trait
@test conversion_trait(Image) === ImageLike()
@test conversion_trait(Heatmap) === CellBasedGrid()
@test conversion_trait(Surface) === VertexBasedGrid()
@test conversion_trait(Contour) === VertexBasedGrid()
@test conversion_trait(Contourf) === VertexBasedGrid()

m1 = [x for x in 1:10, y in 1:6]
m2 = [y for x in 1:10, y in 1:6]
m3 = rand(10, 6)

r1 = 1:10
r2 = 1:6

v1 = collect(1:10)
v2 = collect(1:6)

i1 = 1..10
i2 = 1..6

o3 = Float32.(m3)

# Conversions
@testset "ImageLike conversion" begin
@test convert_arguments(Image, m3) == (0f0..10f0, 0f0..6f0, o3)
@test convert_arguments(Image, v1, r2, m3) == (1f0..10f0, 1f0..6f0, o3)
@test convert_arguments(Image, i1, v2, m3) == (1f0..10f0, 1f0..6f0, o3)
@test_throws ErrorException convert_arguments(Image, m1, m2, m3)
@test_throws ErrorException convert_arguments(Heatmap, m1, m2)
end

@testset "VertexBasedGrid conversion" begin
vo1 = Float32.(v1)
vo2 = Float32.(v2)
mo1 = Float32.(m1)
mo2 = Float32.(m2)
@test convert_arguments(Surface, m3) == (vo1, vo2, o3)
@test convert_arguments(Contour, i1, v2, m3) == (vo1, vo2, o3)
@test convert_arguments(Contourf, v1, r2, m3) == (vo1, vo2, o3)
@test convert_arguments(Surface, m1, m2, m3) == (mo1, mo2, o3)
@test convert_arguments(Surface, m1, m2) == (mo1, mo2, zeros(Float32, size(o3)))
end

@testset "CellBasedGrid conversion" begin
o1 = Float32.(0.5:1:10.5)
o2 = Float32.(0.5:1:6.5)
@test convert_arguments(Heatmap, m3) == (o1, o2, o3)
@test convert_arguments(Heatmap, r1, i2, m3) == (o1, o2, o3)
@test convert_arguments(Heatmap, v1, r2, m3) == (o1, o2, o3)
@test convert_arguments(Heatmap, 0:10, v2, m3) == (collect(0f0:10f0), o2, o3)
@test_throws ErrorException convert_arguments(Heatmap, m1, m2, m3)
@test_throws ErrorException convert_arguments(Heatmap, m1, m2)
end
end

0 comments on commit 4ad7265

Please sign in to comment.