Simplify tests

This commit is contained in:
Rico Riedel 2022-07-31 16:49:29 +02:00
parent 1f03a8fd13
commit 56e630204a
No known key found for this signature in database
GPG Key ID: 75AC868575DE7B18
2 changed files with 11 additions and 23 deletions

View File

@ -33,34 +33,34 @@ mod test {
fn convert_negative_index() { fn convert_negative_index() {
let converter = ColorConverterImpl::new(vec![Red, Green, Blue]); let converter = ColorConverterImpl::new(vec![Red, Green, Blue]);
assert!(matches!(converter.convert(-0.2), Blue)); assert_eq!(Blue, converter.convert(-0.2));
} }
#[test] #[test]
fn convert_index_zero() { fn convert_index_zero() {
let converter = ColorConverterImpl::new(vec![Red, Green, Blue]); let converter = ColorConverterImpl::new(vec![Red, Green, Blue]);
assert!(matches!(converter.convert(0.0), Red)); assert_eq!(Red, converter.convert(0.0));
} }
#[test] #[test]
fn convert() { fn convert() {
let converter = ColorConverterImpl::new(vec![Red, Green, Blue]); let converter = ColorConverterImpl::new(vec![Red, Green, Blue]);
assert!(matches!(converter.convert(0.5), Green)); assert_eq!(Green, converter.convert(0.5));
} }
#[test] #[test]
fn convert_index_one() { fn convert_index_one() {
let converter = ColorConverterImpl::new(vec![Red, Green, Blue]); let converter = ColorConverterImpl::new(vec![Red, Green, Blue]);
assert!(matches!(converter.convert(1.0), Red)); assert_eq!(Red, converter.convert(1.0));
} }
#[test] #[test]
fn convert_index_above_one() { fn convert_index_above_one() {
let converter = ColorConverterImpl::new(vec![Red, Green, Blue]); let converter = ColorConverterImpl::new(vec![Red, Green, Blue]);
assert!(matches!(converter.convert(1.5), Green)); assert_eq!(Green, converter.convert(1.5));
} }
} }

View File

@ -33,35 +33,23 @@ mod test {
fn convert_keep() { fn convert_keep() {
let converter = LevelConverterImpl::default(); let converter = LevelConverterImpl::default();
assert!(matches!(converter.convert(-0.1), Level::Keep)); assert_eq!(Level::Keep, converter.convert(-0.1));
} }
#[test] #[test]
fn convert_draw() { fn convert_draw() {
let converter = LevelConverterImpl::default(); let converter = LevelConverterImpl::default();
if let Level::Draw(level) = converter.convert(0.0) { assert_eq!(Level::Draw(0.0), converter.convert(0.0));
assert_eq!(0.0, level); assert_eq!(Level::Draw(0.5), converter.convert(0.5));
} else { assert_eq!(Level::Draw(0.9), converter.convert(0.9));
panic!();
}
if let Level::Draw(level) = converter.convert(0.5) {
assert_eq!(0.5, level);
} else {
panic!();
}
if let Level::Draw(level) = converter.convert(0.9) {
assert_eq!(0.9, level);
} else {
panic!();
}
} }
#[test] #[test]
fn convert_clear() { fn convert_clear() {
let converter = LevelConverterImpl::default(); let converter = LevelConverterImpl::default();
assert!(matches!(converter.convert(1.0), Level::Clear)); assert_eq!(Level::Clear, converter.convert(1.0));
assert!(matches!(converter.convert(1.5), Level::Clear)); assert_eq!(Level::Clear, converter.convert(1.5));
} }
} }