Fix char converter

This commit is contained in:
Rico Riedel 2022-08-01 15:33:57 +02:00
parent 393d3dd67e
commit 2943a2514b
No known key found for this signature in database
GPG Key ID: 75AC868575DE7B18

View File

@ -26,14 +26,14 @@ impl CharConverterImpl {
impl CharConverter for CharConverterImpl { impl CharConverter for CharConverterImpl {
fn convert(&self, level: f32) -> CharSample { fn convert(&self, level: f32) -> CharSample {
if level < 0.0 { if level < 0.0 {
CharSample::Keep CharSample::Clear
} else if level < 1.0 { } else if level < 1.0 {
let index = (level * self.count) as usize; let index = (level * self.count) as usize;
let char = self.chars.chars().nth(index).unwrap(); let char = self.chars.chars().nth(index).unwrap();
CharSample::Draw(char) CharSample::Draw(char)
} else { } else {
CharSample::Clear CharSample::Keep
} }
} }
} }
@ -43,10 +43,10 @@ mod test {
use super::*; use super::*;
#[test] #[test]
fn convert_keep() { fn convert_clear() {
let converter = CharConverterImpl::new("abc".to_string()); let converter = CharConverterImpl::new("abc".to_string());
assert_eq!(CharSample::Keep, converter.convert(-0.1)); assert_eq!(CharSample::Clear, converter.convert(-0.1));
} }
#[test] #[test]
@ -59,10 +59,10 @@ mod test {
} }
#[test] #[test]
fn convert_clear() { fn convert_keep() {
let converter = CharConverterImpl::new("123".to_string()); let converter = CharConverterImpl::new("123".to_string());
assert_eq!(CharSample::Clear, converter.convert(1.0)); assert_eq!(CharSample::Keep, converter.convert(1.0));
assert_eq!(CharSample::Clear, converter.convert(1.5)); assert_eq!(CharSample::Keep, converter.convert(1.5));
} }
} }