Add more unit tests

This commit is contained in:
Rico Riedel 2022-08-05 19:22:52 +02:00
parent 7c13c8838a
commit d965ba413a
No known key found for this signature in database
GPG Key ID: 75AC868575DE7B18

View File

@ -54,6 +54,34 @@ mod test {
SegmentsFactory::new(Box::new(child), 2).create(&config); SegmentsFactory::new(Box::new(child), 2).create(&config);
} }
#[test]
fn sample_above_one_untouched() {
let mut child = MockPatternFactory::new();
child.expect_create().returning(|_| {
let mut sampler = MockPattern::new();
sampler.expect_sample().return_const(1.1);
Box::new(sampler)
});
let sampler = SegmentsFactory::new(Box::new(child), 3).create(&Config::default());
assert_abs_diff_eq!(1.1, sampler.sample(Vector::default()));
}
#[test]
fn sample_below_zero_untouched() {
let mut child = MockPatternFactory::new();
child.expect_create().returning(|_| {
let mut sampler = MockPattern::new();
sampler.expect_sample().return_const(-0.1);
Box::new(sampler)
});
let sampler = SegmentsFactory::new(Box::new(child), 3).create(&Config::default());
assert_abs_diff_eq!(-0.1, sampler.sample(Vector::default()));
}
#[test] #[test]
fn sample_second_segment_begins_with_one() { fn sample_second_segment_begins_with_one() {
let mut child = MockPatternFactory::new(); let mut child = MockPatternFactory::new();