#42 - Fixed the safe_hex_color function. #76
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#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))