about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander <alexanderkabua@gmail.com>2022-04-26 11:35:26 +0300
committerAlexander <alexanderkabua@gmail.com>2022-04-26 11:35:26 +0300
commit361b23e687fa9416919c43fa993d58f94bd6c47a (patch)
treed4b23dfc51fad1bf1be47a2a1f01632878218b3e /src
parentbcde82bf3521a16c8a08d2d293d374c01cdd247c (diff)
downloadcorrelation_rust-361b23e687fa9416919c43fa993d58f94bd6c47a.tar.gz
bring modules to scope add tests
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs39
1 files changed, 36 insertions, 3 deletions
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