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

Fix bounds check for Color8::new_rgb #13

Merged
merged 2 commits into from Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/colors.rs
Expand Up @@ -184,7 +184,7 @@ impl Color8 {

/// New RGB color, each channel in range `0..6`
pub fn new_rgb(r: u8, g: u8, b: u8) -> Result<Self, OutOfBoundsError> {
if r < 6 || g < 6 || b < 6 {
if r < 6 && g < 6 && b < 6 {
Ok(Self {
byte: 16 + r * 36 + g * 6 + b,
})
Expand Down
8 changes: 8 additions & 0 deletions tests/tests.rs
Expand Up @@ -125,3 +125,11 @@ fn convert_rgb_to_color8() {
fn convert_gray_to_color8() {
assert_eq!(Color8::new_gray(23).unwrap(), Color8::new(255));
}

#[test]
fn color8_new_rgb() {
assert!(Color8::new_rgb(6, 5, 5).is_err());
assert!(Color8::new_rgb(5, 6, 5).is_err());
assert!(Color8::new_rgb(5, 5, 6).is_err());
assert!(Color8::new_rgb(5, 5, 5).is_ok());
}