mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-15 20:46:40 +00:00
Add shift unit tests
This commit is contained in:
parent
cbb0c532e2
commit
726f482687
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user