From b0021b27cebf31b484114ce23458ef4d58b2c2c7 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Tue, 19 Mar 2024 12:11:42 -0700 Subject: [PATCH] Update tests with comments --- test/runtests.jl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 6478109..d12702a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -12,7 +12,7 @@ buffer = deepcopy(pixel_points) @testset "SwarmMakie.jl" begin @testset "Algorithms run without error" begin - for algorithm in [NoBeeswarm(), SimpleBeeswarm(), WilkinsonBeeswarm()] + for algorithm in [NoBeeswarm(), SimpleBeeswarm(), WilkinsonBeeswarm(), UniformJitter(), PseudorandomJitter(), QuasirandomJitter()] @test_nowarn begin SwarmMakie.calculate!(buffer, algorithm, pixel_points, 10, :left) end @@ -28,6 +28,11 @@ buffer = deepcopy(pixel_points) Makie.update_state_before_display!(f) Makie.update_state_before_display!(f) img = Makie.colorbuffer(f.scene; screen_config = CairoMakie.ScreenConfig(1, 1, :none, true, false)) + # We have a matrix of all colors in the image. Now, what we do is the following: + # The color white in RGBf is (1, 1, 1). For a color to be red, the blue and green components + # must correspondingly decrease, since the RGBf values cannot exceed 1. + # So, we know if a red pixel with alpha=0.5 is rendered, the blue value there will be between 0.6 and 0.4. + # If more than one marker is rendered, the red is more intense and the blue value will be even less than 4. nonwhite_pixels = 0 overlap_pixels = 0 for pixel in img @@ -38,18 +43,21 @@ buffer = deepcopy(pixel_points) overlap_pixels += 1 end end - @test overlap_pixels/nonwhite_pixels < 0.07 # 7% overlap should be our ideal for this sort of data + @test overlap_pixels/nonwhite_pixels < 0.07 # 7% overlap should be our ideal for this sort of data - this is totally arbitrary. end end @testset "Gutters" begin + # First, we test the regular gutter with multiple categories. f, a, p = beeswarm(rand(1:3, 300), randn(300); color = rand(RGBAf, 300), markersize = 20, algorithm = SimpleBeeswarm()) Makie.update_state_before_display!(f) Makie.update_state_before_display!(f) @test_warn "Gutter threshold exceeded" p.gutter = 0.5 + # Next, we test it in direction y f, a, p = beeswarm(rand(1:3, 300), randn(300); direction = :x, color = rand(RGBAf, 300), markersize = 20, algorithm = SimpleBeeswarm()) Makie.update_state_before_display!(f) Makie.update_state_before_display!(f) @test_warn "Gutter threshold exceeded" p.gutter = 0.5 + # and it shouldn't warn if, when using a lower markersize, the gutter is not reached. f, a, p = beeswarm(rand(1:3, 300), randn(300); direction = :y, color = rand(RGBAf, 300), markersize = 9, algorithm = SimpleBeeswarm()) Makie.update_state_before_display!(f) Makie.update_state_before_display!(f) @@ -58,5 +66,5 @@ buffer = deepcopy(pixel_points) end # TODO: -# - Test gutters when added # - Test that the order of points is preserved +# How to do this? Test y values for SimpleBeeswarm and use StatsBase.histogram to test WilkinsonBeeswarm. Jitter should just make sure y coordinates are preserved.