fix palette tests

This commit is contained in:
Max Bradbury 2021-11-14 18:05:09 +00:00
parent 955645415d
commit 8ca5acc240
1 changed files with 9 additions and 24 deletions

View File

@ -177,6 +177,7 @@ impl Palette {
Self { name, colours }
}
/// todo maybe this should be Into<DynamicImage>
pub fn to_png(&self) -> DynamicImage {
let mut image = DynamicImage::new_rgb8(
self.colours.len() as u32, 1 as u32
@ -194,29 +195,13 @@ impl Palette {
#[cfg(test)]
mod test {
use std::path::PathBuf;
use crate::{Colour, Palette};
use crate::Palette;
#[test]
fn palette_from_jasc() {
let path = PathBuf::from("src/test-resources/basic/palettes/soup11.pal");
let path = PathBuf::from("src/test-resources/palettes/soup11.pal");
let output = Palette::from_jasc(path);
let expected = Palette {
name: "soup11".into(),
colours: vec![
Colour { red: 79, green: 30, blue: 69 },
Colour { red: 150, green: 48, blue: 87 },
Colour { red: 215, green: 68, blue: 89 },
Colour { red: 235, green: 112, blue: 96 },
Colour { red: 255, green: 179, blue: 131 },
Colour { red: 255, green: 255, blue: 255 },
Colour { red: 127, green: 227, blue: 187 },
Colour { red: 92, green: 187, blue: 196 },
Colour { red: 69, green: 126, blue: 163 },
Colour { red: 56, green: 66, blue: 118 },
Colour { red: 50, green: 36, blue: 81 }
]
};
let expected = crate::mock::palette::soup11();
assert_eq!(output, expected);
}
@ -230,7 +215,7 @@ mod test {
#[test]
fn palette_from_gpl() {
let path = PathBuf::from("src/test-resources/basic/palettes/soup11.gpl");
let path = PathBuf::from("src/test-resources/palettes/soup11.gpl");
let output = Palette::from_gpl(path);
let expected = crate::mock::palette::soup11();
@ -247,7 +232,7 @@ mod test {
#[test]
fn palette_from_txt() {
let path = PathBuf::from("src/test-resources/basic/palettes/soup11.txt");
let path = PathBuf::from("src/test-resources/palettes/soup11.txt");
let output = Palette::from_txt(path);
let expected = crate::mock::palette::soup11();
assert_eq!(output, expected);
@ -263,7 +248,7 @@ mod test {
#[test]
fn palette_from_hex() {
let path = PathBuf::from("src/test-resources/basic/palettes/soup11.hex");
let path = PathBuf::from("src/test-resources/palettes/soup11.hex");
let output = Palette::from_hex(path);
let expected = crate::mock::palette::soup11();
assert_eq!(output, expected);
@ -278,7 +263,7 @@ mod test {
#[test]
fn palette_from_png() {
let path = PathBuf::from("src/test-resources/basic/palettes/soup11.png");
let path = PathBuf::from("src/test-resources/palettes/soup11.png");
let output = Palette::from_png(path);
let expected = crate::mock::palette::soup11();
assert_eq!(output, expected);
@ -289,7 +274,7 @@ mod test {
use image::io::Reader as ImageReader;
let output = crate::mock::palette::soup11().to_png();
let path = PathBuf::from("src/test-resources/basic/palettes/soup11.png");
let path = PathBuf::from("src/test-resources/palettes/soup11.png");
let expected = ImageReader::open(path).unwrap().decode().unwrap();
assert_eq!(output, expected);
}