use samplics::sampling::{EqualProbability, Population, UnstratifiedSample}; #[test] fn srs_sample() { let y: Vec = vec![10.0, 20.0, 30.0, 40.0, 50.0]; let pop = Population::new(y, None, None); let samp_size1 = 2; let mut srs_sample1 = UnstratifiedSample::new(samp_size1, false, None); assert!(srs_sample1.samp_size == 2); assert!(srs_sample1.pop_size == None); assert!(srs_sample1.fpc == 0.0); assert!(srs_sample1.with_replacement == false); srs_sample1.select(&pop, Some(7)); assert!(srs_sample1.index == vec![1, 4]); assert!(srs_sample1.y == vec![20.0, 50.0]); assert!(srs_sample1.pop_size == Some(pop.y.len())); assert!(srs_sample1.fpc == samp_size1 as f64 / srs_sample1.pop_size.unwrap() as f64); srs_sample1.calculate_probs(); assert!(srs_sample1.probs.unwrap() == vec![2f64 / 5f64, 1f64 / 5f64]); let samp_size2 = 3; let mut srs_sample2: UnstratifiedSample = UnstratifiedSample::new(samp_size2, true, None); assert!(srs_sample2.samp_size == 3); assert!(srs_sample2.pop_size == None); assert!(srs_sample2.fpc == 0.0); assert!(srs_sample2.with_replacement == true); srs_sample2.select(&pop, Some(15)); assert!(srs_sample2.index == vec![3, 1, 3]); assert!(srs_sample2.y == vec![40.0, 20.0, 40.0]); assert!(srs_sample2.pop_size == Some(pop.y.len())); assert!(srs_sample2.fpc == samp_size2 as f64 / srs_sample2.pop_size.unwrap() as f64); }