From 532900261597f70befd5bfebfe199689d3f7f0bd Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 18 May 2022 14:15:38 +0300 Subject: code formatting --- src/correlations.rs | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/correlations.rs b/src/correlations.rs index e938fb2..715f21c 100644 --- a/src/correlations.rs +++ b/src/correlations.rs @@ -117,6 +117,23 @@ impl<'a> Compute<'a> { } } + + + pub fn filter_top(result:Vec<(f64,f64)>,n:Option) -> Vec<(f64,f64)>{ + + match n{Some(n_top) => { + + result + } + + None => + { + result + + } + } + } + pub fn sorter(results:&mut Vec<(f64,f64)>){ //naive sorter @@ -358,13 +375,21 @@ mod test { //for tests only let compute_obj = Compute::new( + ',', + "pearson", + "/home/kabui/correlation_rust/src/matrix_80.txt", + &x_vals, + ); + + let computation2 = Compute::new( ',', "pearson", "/home/kabui/correlation_rust/src/db300.txt", &x_vals, ); - //assert_eq!(vec![(1.2, 1.5)], compute_obj.compute()) + assert_eq!(vec![(1.2, 1.5)], compute_obj.compute()); + assert_eq!(vec![(1.2,1.5)],computation2.compute()); } #[test] @@ -380,5 +405,19 @@ mod test { assert_eq!(f,vec![(1.2, 11.1), (9.3, 11.1), (1.1, 9.7), (11.1, 7.8), (1.3, 7.0), (1.2, 1.0), (1.3, 0.5)]); + } + + #[test] + fn test_n_top(){ + + let mut a1 = vec![(1.2,1.0),(1.3,0.5),(1.3,7.)]; + + let new_vec = Compute::filter_top(a1, Some(2)); + + assert_eq!(new_vec,vec![(1.2,1.0),(1.3,0.5)]) + + + + } } -- cgit 1.4.1