Fix hex converter
This commit is contained in:
parent
50603b4325
commit
8c8195de89
13
src/color.rs
13
src/color.rs
@ -39,7 +39,7 @@ impl Color {
|
||||
|
||||
pub fn to_hex(&self) -> String {
|
||||
format!(
|
||||
"#{:X}{:X}{:X}",
|
||||
"#{:02X}{:02X}{:02X}",
|
||||
(self.0 * 255.0) as u8,
|
||||
(self.1 * 255.0) as u8,
|
||||
(self.2 * 255.0) as u8
|
||||
@ -150,3 +150,14 @@ impl ColorModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_to_hex() {
|
||||
let col = Color(0.0, 1.0, 0.0);
|
||||
assert_eq!("#00FF00", &col.to_hex());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user