Skip to content

Commit

Permalink
Update tests with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
asinghvi17 authored Mar 19, 2024
1 parent 69e4b54 commit b0021b2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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.

2 comments on commit b0021b2

@asinghvi17
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

This is the first release of SwarmMakie.jl!

It exports the beeswarm Makie recipe and several different algorithms, including the default SimpleBeeswarm, Leland Wilkinson's original "dot-histogram" approach with WilkinsonBeeswarm, and three generic jitter algorithms.

Further progress will be forthcoming, including dodging and better limits finding! Stay tuned.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/103215

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.0.1 -m "<description of version>" b0021b27cebf31b484114ce23458ef4d58b2c2c7
git push origin v0.0.1

Please sign in to comment.