From 361b23e687fa9416919c43fa993d58f94bd6c47a Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 26 Apr 2022 11:35:26 +0300 Subject: bring modules to scope add tests --- src/lib.rs | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 71b2da2..8beb0e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,16 @@ +pub mod reader; use rgsl::{ randist::t_distribution::{tdist_P, tdist_Q}, statistics::{correlation, spearman}, }; - use assert_approx_eq::assert_approx_eq; +use reader::{ + file_reader, + add_numbers_2 +}; + + trait Correlation { fn correlate(&self,x:&[f64],y:&[f64]) ->(f64,f64); @@ -77,6 +83,11 @@ impl Correlation for Spearman { fn correlate(&self,x:&[f64],y:&[f64]) -> (f64,f64){ + match x.len() == y.len() { + true => println!("success"), + false => panic!("array should be of the same size") + }; + //dditional workspace of size 2*n is required in work let mut vec = Vec::with_capacity(2 * self.n); let workspace: &mut [f64] = vec.as_mut_slice(); @@ -95,6 +106,8 @@ impl Correlation for Spearman { #[cfg(test)] mod tests { + use crate::reader::add_numbers_2; + use super::*; #[test] fn test_add_numbers() { @@ -102,7 +115,7 @@ mod tests { } #[test] - fn test_pearson(){ + fn test_pearson_obj(){ let new_pearson = Pearson::new(5); assert_eq!(new_pearson,Pearson{n:5, degrees_of_freedom:3.0}); } @@ -116,7 +129,7 @@ mod tests { } #[test] - fn test_spearman(){ + fn test_spearman_obj(){ let new_spearman = Spearman::new(5); assert_eq!(new_spearman,Spearman{n:5, degrees_of_freedom:3.0}); @@ -134,4 +147,24 @@ mod tests { } + + #[test] + fn test_add_2(){ + assert_eq!(add_numbers_2(4, 5),9) + } + + #[test] + + fn test_file_reader_error(){ + assert!(file_reader("./non_file.txt").is_err()); + } + + + #[test] + + fn test_file_reader() { + let expected_results = file_reader("./mock_dataset.txt"); + + assert!(expected_results.is_ok()) + } } \ No newline at end of file -- cgit 1.4.1