fix palette tests
This commit is contained in:
parent
955645415d
commit
8ca5acc240
|
@ -177,6 +177,7 @@ impl Palette {
|
||||||
Self { name, colours }
|
Self { name, colours }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// todo maybe this should be Into<DynamicImage>
|
||||||
pub fn to_png(&self) -> DynamicImage {
|
pub fn to_png(&self) -> DynamicImage {
|
||||||
let mut image = DynamicImage::new_rgb8(
|
let mut image = DynamicImage::new_rgb8(
|
||||||
self.colours.len() as u32, 1 as u32
|
self.colours.len() as u32, 1 as u32
|
||||||
|
@ -194,29 +195,13 @@ impl Palette {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use crate::{Colour, Palette};
|
use crate::Palette;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn palette_from_jasc() {
|
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 output = Palette::from_jasc(path);
|
||||||
|
let expected = crate::mock::palette::soup11();
|
||||||
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 }
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
|
@ -230,7 +215,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn palette_from_gpl() {
|
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 output = Palette::from_gpl(path);
|
||||||
let expected = crate::mock::palette::soup11();
|
let expected = crate::mock::palette::soup11();
|
||||||
|
|
||||||
|
@ -247,7 +232,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn palette_from_txt() {
|
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 output = Palette::from_txt(path);
|
||||||
let expected = crate::mock::palette::soup11();
|
let expected = crate::mock::palette::soup11();
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
|
@ -263,7 +248,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn palette_from_hex() {
|
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 output = Palette::from_hex(path);
|
||||||
let expected = crate::mock::palette::soup11();
|
let expected = crate::mock::palette::soup11();
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
|
@ -278,7 +263,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn palette_from_png() {
|
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 output = Palette::from_png(path);
|
||||||
let expected = crate::mock::palette::soup11();
|
let expected = crate::mock::palette::soup11();
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
|
@ -289,7 +274,7 @@ mod test {
|
||||||
use image::io::Reader as ImageReader;
|
use image::io::Reader as ImageReader;
|
||||||
|
|
||||||
let output = crate::mock::palette::soup11().to_png();
|
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();
|
let expected = ImageReader::open(path).unwrap().decode().unwrap();
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue