Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#42 - Fixed the safe_hex_color function. #76

Merged
merged 3 commits into from
May 16, 2018
Merged

Conversation

kylevoyto
Copy link
Contributor

#42 - Fixed the safe_hex_color function.

Description

The safe_hex_color function used to generate a color using the same approach as the Python faker method. I modified the function to generate only the 216 colors referenced in https://en.wikipedia.org/wiki/Web_colors#Web-safe_colors. I use the approach, "For this method I think generating three separate hex digits and duplicating them and concatenating them would be a cleaner implementation", referenced in ropensci/software-review#94.

Related Issue

fix #42. Also #18 should already be fixed from a previous commit.

Example

res <- ch_safe_hex_color(100000)
plot(table(res) / length(res))

Many tests were added for the ColorProvider functions. The few below reflect the safe_hex_color change:
safe_hex_regex <- "^#([0369CF])\1([0369CF])\2([0369CF])\3$"
expect_match(ch_safe_hex_color(), safe_hex_regex, ignore.case = TRUE)
expect_match(ch_safe_hex_color(12), safe_hex_regex, ignore.case = TRUE)
expect_true(all(nchar(ch_safe_hex_color()) == 7))
expect_true(all(nchar(ch_safe_hex_color(12)) == 7))

The safe_hex_colors function had a bug where values like "#4400#4400" would be returned. There was also an uncertain definition of a "safe" color. I implemented the definition from https://en.wikipedia.org/wiki/Web_colors#Web-safe_colors.
@codecov-io
Copy link

codecov-io commented May 15, 2018

Codecov Report

Merging #76 into master will increase coverage by 0.49%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #76      +/-   ##
==========================================
+ Coverage   61.99%   62.48%   +0.49%     
==========================================
  Files          43       43              
  Lines        1113     1117       +4     
==========================================
+ Hits          690      698       +8     
+ Misses        423      419       -4
Impacted Files Coverage Δ
R/color-provider.R 93.54% <100%> (+0.95%) ⬆️
R/color.R 100% <0%> (+10.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1d20338...513ad87. Read the comment docs.

@sckott sckott added this to the v0.2 milestone May 15, 2018
@sckott
Copy link
Collaborator

sckott commented May 16, 2018

thanks again @kylevoyto thanks for adding all those tests!

@sckott sckott merged commit 6442965 into ropensci:master May 16, 2018
@kylevoyto kylevoyto deleted the issue42 branch May 16, 2018 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix safe colors
3 participants