use peak_finder::data::FourierData; use std::collections::HashMap; mod file_setup; #[test] fn test_iter() { let get_test_file_handle = file_setup::setup_fourier().unwrap(); let mut test_file: FourierData = FourierData::new(get_test_file_handle, 4.0_f32).unwrap(); assert_eq!(test_file.next(), Some((3.000, 4.060))); assert_eq!(test_file.next(), Some((3.001, 5.120))); assert_eq!(test_file.next(), Some((4.002, 4.240))); assert_eq!(test_file.next(), Some((10.123, 4.360))); assert_eq!(test_file.next(), None); } #[test] fn test_threshold() { let get_test_file_handle = file_setup::setup_fourier().unwrap(); let test_file: FourierData = FourierData::new(get_test_file_handle, 4.0_f32).unwrap(); assert_eq!(test_file.data.len(), 4); } #[test] fn test_all_local_maxima() { let get_test_file_handle = file_setup::setup_fourier().unwrap(); let test_file: FourierData = FourierData::new(get_test_file_handle, 0.0).unwrap(); let test_hashmap: HashMap = FourierData::all_local_maxima(&test_file).unwrap(); let mut reference_hashmap: HashMap = HashMap::new(); reference_hashmap.insert(3_usize, (3.001, 5.120)); reference_hashmap.insert(8_usize, (10.123, 4.360)); assert_eq!(test_hashmap, reference_hashmap); } #[test] fn test_mean_intensities() { let get_test_file_handle = file_setup::setup_fourier().unwrap(); let test_file: FourierData = FourierData::new(get_test_file_handle, 4.0_f32).unwrap(); assert_eq!( (4.060 + 5.120 + 4.240 + 4.360) / 4.0_f32, FourierData::mean_intensities(&test_file) ); } #[test] fn test_variance_intensities() { let get_test_file_handle = file_setup::setup_fourier().unwrap(); let test_file: FourierData = FourierData::new(get_test_file_handle, 4.0_f32).unwrap(); let mean = (4.060 + 5.120 + 4.240 + 4.360) / 4.0_f32; let std = ((4.060 - mean).powi(2) + (5.120 - mean).powi(2) + (4.240 - mean).powi(2) + (4.360 - mean).powi(2)) / 4.0_f32; assert_eq!( std, FourierData::variance_intensities( test_file.clone(), FourierData::mean_intensities(&test_file) ) ); } #[test] fn test_shift_energies() { let get_test_file_handle = file_setup::setup_fourier().unwrap(); let mut test_file: FourierData = FourierData::new(get_test_file_handle, 4.0_f32).unwrap(); FourierData::shift_energies(&mut test_file, 2.0_f32); assert_eq!(test_file.next(), Some((5.000, 4.060))); assert_eq!(test_file.next(), Some((5.001, 5.120))); assert_eq!(test_file.next(), Some((6.002, 4.240))); assert_eq!(test_file.next(), Some((12.123, 4.360))); assert_eq!(test_file.next(), None); }