Fix hex converter

This commit is contained in:
daa84 2017-11-16 17:25:59 +03:00
parent 50603b4325
commit 8c8195de89
1 changed files with 12 additions and 1 deletions

View File

@ -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());
}
}