Add shift unit tests

This commit is contained in:
Rico Riedel 2022-08-05 19:07:22 +02:00
parent cbb0c532e2
commit 726f482687
No known key found for this signature in database
GPG Key ID: 75AC868575DE7B18

View File

@ -23,3 +23,62 @@ impl Pattern for Shift {
self.child.sample(pos) + 1.0 - 2.0 * self.shift
}
}
#[cfg(test)]
mod test {
use super::*;
use crate::MockPatternFactory;
use mockall::predicate::eq;
#[test]
fn create_config_correct() {
let config = Config {
size: Vector::new(4.0, 2.0),
step: 0.4,
};
let mut child = MockPatternFactory::new();
child
.expect_create()
.with(eq(config))
.once()
.returning(|_| Box::new(MockPattern::new()));
ShiftFactory::new(Box::new(child)).create(&config);
}
#[test]
fn sample_shifted() {
let config = Config {
size: Vector::default(),
step: 0.4,
};
let mut child = MockPatternFactory::new();
child.expect_create().returning(|_| {
let mut sampler = MockPattern::new();
sampler.expect_sample().return_const(0.6);
Box::new(sampler)
});
let sampler = ShiftFactory::new(Box::new(child)).create(&config);
assert_eq!(0.8, sampler.sample(Vector::default()));
}
#[test]
fn sample_pos_correct() {
let mut child = MockPatternFactory::new();
child.expect_create().once().returning(|_| {
let mut sampler = MockPattern::new();
sampler
.expect_sample()
.with(eq(Vector::new(6.0, 7.0)))
.once()
.return_const(0.0);
Box::new(sampler)
});
let sampler = ShiftFactory::new(Box::new(child)).create(&Config::default());
sampler.sample(Vector::new(6.0, 7.0));
}
}