From d965ba413af984e6ae5a2036e692f264b6b6804d Mon Sep 17 00:00:00 2001 From: Rico Riedel Date: Fri, 5 Aug 2022 19:22:52 +0200 Subject: [PATCH] Add more unit tests --- src/transform/segment.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/transform/segment.rs b/src/transform/segment.rs index e659b6f..22934ab 100644 --- a/src/transform/segment.rs +++ b/src/transform/segment.rs @@ -54,6 +54,34 @@ mod test { 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] fn sample_second_segment_begins_with_one() { let mut child = MockPatternFactory::new();