forked from JuliaGraphics/Colors.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
112 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
using Test, Colors | ||
|
||
@testset "Algorithms" begin | ||
@test isconcretetype(eltype(colormap("Grays"))) | ||
|
||
@test_throws ArgumentError colormap("Grays", N=10) | ||
# issue 346 | ||
msc_h_diff = 0 | ||
for hsv_h in 0:0.1:360 | ||
hsv = HSV(hsv_h, 1.0, 1.0) # most saturated | ||
lch = convert(LCHuv, hsv) | ||
msc = MSC(lch.h) | ||
msc_h_diff = max(msc_h_diff, colordiff(msc, lch)) | ||
end | ||
@test msc_h_diff < 1 | ||
|
||
@test MSC(0, 100) ≈ 0 | ||
@test MSC(0, 0) ≈ 0 | ||
|
||
col = distinguishable_colors(10) | ||
@test isconcretetype(eltype(col)) | ||
local mindiff | ||
mindiff = Inf | ||
for i = 1:10 | ||
for j = i+1:10 | ||
mindiff = min(mindiff, colordiff(col[i], col[j])) | ||
end | ||
msc_h_l_sat = 1 | ||
for h = 0:0.1:359.9, l = 1:1:99 | ||
c = MSC(h, l) | ||
hsv = convert(HSV, LCHuv(l, c, h)) | ||
msc_h_l_sat = min(msc_h_l_sat, max(hsv.s, hsv.v)) | ||
end | ||
@test mindiff > 8 | ||
@test msc_h_l_sat > 1 - 1e-4 | ||
|
||
cols = distinguishable_colors(1) | ||
@test colordiff(distinguishable_colors(1, cols; dropseed=true)[1], cols[1]) > 50 | ||
# issue 346 | ||
@test MSC(0, 90, linear=true) > MSC(0, 90) | ||
@test MSC(280, 50, linear=true) < MSC(280, 50) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,45 @@ | ||
@testset "Colormaps" begin | ||
@test length(colormap("RdBu", 100)) == 100 | ||
|
||
@test isconcretetype(eltype(colormap("Grays"))) | ||
|
||
@test_throws ArgumentError colormap("Grays", N=10) | ||
|
||
# The outputs of `colormap()` were slightly affected by the bug fix of | ||
# `MSC(h)` (issue #349). | ||
# The following were generated by `colormap()` in Colors.jl v0.9.6. | ||
blues_old = ["F4FDFF", "B3E3F4", "65B9E7", "2978BE", "0B2857"] | ||
greens_old = ["FAFFF7", "B6EEA0", "75C769", "308B40", "00391A"] | ||
grays_old = ["FFFFFF", "DCDCDC", "A9A9A9", "626262", "000000"] | ||
oranges_old = ["FFFBF6", "FFD6B4", "FF9D5F", "E2500D", "732108"] | ||
purples_old = ["FBFBFB", "DBD7F6", "AFA7E6", "7666BF", "3C0468"] | ||
reds_old = ["FFF1EE", "FFC4B9", "FF8576", "E72823", "6D0B0C"] | ||
rdbu_old = ["610102", "FF8D7B", "F9F8F9", "76B4E8", "092C58"] | ||
|
||
to_rgb(s) = parse(RGB, "#"*s) | ||
max_colordiff(a1, a2) = reduce(max, colordiff.(a1, a2)) | ||
@test max_colordiff(colormap("Blues", 5), to_rgb.(blues_old)) < 1 | ||
@test max_colordiff(colormap("Greens", 5), to_rgb.(greens_old)) < 1 | ||
@test max_colordiff(colormap("Grays", 5), to_rgb.(grays_old)) < 1 | ||
@test max_colordiff(colormap("Oranges", 5), to_rgb.(oranges_old)) < 1 | ||
@test max_colordiff(colormap("Purples", 5), to_rgb.(purples_old)) < 1 | ||
@test max_colordiff(colormap("Reds", 5), to_rgb.(reds_old)) < 1 | ||
@test max_colordiff(colormap("RdBu", 5), to_rgb.(rdbu_old)) < 1 | ||
|
||
# TODO: add more tests | ||
|
||
col = distinguishable_colors(10) | ||
@test isconcretetype(eltype(col)) | ||
local mindiff | ||
mindiff = Inf | ||
for i = 1:10 | ||
for j = i+1:10 | ||
mindiff = min(mindiff, colordiff(col[i], col[j])) | ||
end | ||
end | ||
@test mindiff > 8 | ||
|
||
cols = distinguishable_colors(1) | ||
@test colordiff(distinguishable_colors(1, cols; dropseed=true)[1], cols[1]) > 50 | ||
|
||
end |