mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-22 16:06:38 +00:00
Add invert unit tests
This commit is contained in:
parent
6d60ef0088
commit
cbb0c532e2
@ -10,12 +10,13 @@ pub use wheel::*;
|
|||||||
|
|
||||||
use crate::Vector;
|
use crate::Vector;
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
#[derive(Copy, Clone, Default, PartialEq, Debug)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub size: Vector,
|
pub size: Vector,
|
||||||
pub step: f32,
|
pub step: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(test, mockall::automock)]
|
||||||
pub trait PatternFactory {
|
pub trait PatternFactory {
|
||||||
fn create(&self, config: &Config) -> Box<dyn Pattern>;
|
fn create(&self, config: &Config) -> Box<dyn Pattern>;
|
||||||
}
|
}
|
||||||
|
@ -25,3 +25,61 @@ impl Pattern for Invert {
|
|||||||
1.0 - self.child.sample(pos)
|
1.0 - self.child.sample(pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
use crate::MockPatternFactory;
|
||||||
|
use mockall::predicate::eq;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn create_config_correct() {
|
||||||
|
let input = Config {
|
||||||
|
size: Vector::new(4.0, 2.0),
|
||||||
|
step: 0.4,
|
||||||
|
};
|
||||||
|
let mut output = input.clone();
|
||||||
|
output.step = 0.6;
|
||||||
|
|
||||||
|
let mut child = MockPatternFactory::new();
|
||||||
|
child
|
||||||
|
.expect_create()
|
||||||
|
.with(eq(output))
|
||||||
|
.once()
|
||||||
|
.returning(|_| Box::new(MockPattern::new()));
|
||||||
|
|
||||||
|
InvertFactory::new(Box::new(child)).create(&input);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sample_inverted() {
|
||||||
|
let mut child = MockPatternFactory::new();
|
||||||
|
child.expect_create().returning(|_| {
|
||||||
|
let mut sampler = MockPattern::new();
|
||||||
|
sampler.expect_sample().return_const(0.7);
|
||||||
|
Box::new(sampler)
|
||||||
|
});
|
||||||
|
|
||||||
|
let sampler = InvertFactory::new(Box::new(child)).create(&Config::default());
|
||||||
|
|
||||||
|
assert_eq!(0.3, 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(4.0, 2.0)))
|
||||||
|
.once()
|
||||||
|
.return_const(0.0);
|
||||||
|
Box::new(sampler)
|
||||||
|
});
|
||||||
|
|
||||||
|
let sampler = InvertFactory::new(Box::new(child)).create(&Config::default());
|
||||||
|
|
||||||
|
sampler.sample(Vector::new(4.0, 2.0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user