Skip to content

Commit 39feb7e

Browse files
b-maorottier
authored andcommitted
fix: unwanted panic at Analiser initialization
1 parent 9cf136d commit 39feb7e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/analysis.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ impl Analyser {
188188
ring_buffer,
189189
fft_size: DEFAULT_FFT_SIZE,
190190
smoothing_time_constant: DEFAULT_SMOOTHING_TIME_CONSTANT,
191-
min_decibels: DEFAULT_MIN_DECIBELS,
192-
max_decibels: DEFAULT_MAX_DECIBELS,
191+
min_decibels: f64::NEG_INFINITY,
192+
max_decibels: f64::INFINITY,
193193
fft_planner: Mutex::new(fft_planner),
194194
fft_input,
195195
fft_scratch,
@@ -636,16 +636,25 @@ mod tests {
636636
#[should_panic]
637637
fn test_min_decibels_constraints_lt_max_decibels() {
638638
let mut analyser = Analyser::new();
639+
analyser.set_max_decibels(DEFAULT_MAX_DECIBELS); // init value
639640
analyser.set_min_decibels(DEFAULT_MAX_DECIBELS);
640641
}
641642

642643
#[test]
643644
#[should_panic]
644645
fn test_max_decibels_constraints_lt_min_decibels() {
645646
let mut analyser = Analyser::new();
647+
analyser.set_min_decibels(DEFAULT_MIN_DECIBELS); // init value
646648
analyser.set_max_decibels(DEFAULT_MIN_DECIBELS);
647649
}
648650

651+
#[test]
652+
fn test_min_max_decibels_init() {
653+
let mut analyser = Analyser::new();
654+
analyser.set_min_decibels(-10.);
655+
analyser.set_max_decibels(20.);
656+
}
657+
649658
#[test]
650659
fn test_get_float_time_domain_data_vs_fft_size() {
651660
// dst is bigger than fft_size

0 commit comments

Comments
 (0)