about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander <alexanderkabua@gmail.com>2022-04-27 20:30:50 +0300
committerAlexander <alexanderkabua@gmail.com>2022-04-27 20:30:50 +0300
commitef2de72b9afd00df2d2fdc59044dc8e2fbfee5c6 (patch)
treeaccb991784789cb220167cd824913626acf5ceef /src
parent43997cd36e6a63c58cfde50fa0ea3ae640c790a1 (diff)
downloadcorrelation_rust-ef2de72b9afd00df2d2fdc59044dc8e2fbfee5c6.tar.gz
unittest for creating correlation obj
Diffstat (limited to 'src')
-rw-r--r--src/correlations.rs63
1 files changed, 58 insertions, 5 deletions
diff --git a/src/correlations.rs b/src/correlations.rs
index 4a516b3..506f807 100644
--- a/src/correlations.rs
+++ b/src/correlations.rs
@@ -132,26 +132,39 @@ mod test{
 //structure we need file for y vals,x_val ,correlation method to use
 
 
+
+#[allow(dead_code)]
+
+#[derive(PartialEq,Debug)]
 struct Compute <'a>{
     x_vals:&'a [f64],
     dataset_path:&'a str,
     method: CorrelationMethod
 
 }
-
+#[allow(dead_code)]
 impl <'a> Compute<'a>{
     fn new (method:&str,dataset_path:&'a str,x_vals:&'a [f64]) -> Self{
+        //capitalize method/same cases
+
+        let method = match method {
+            "pearson" => CorrelationMethod::Pearson,
+            "spearman" => CorrelationMethod::Spearman,
+            _ => panic!("method cannot be found")
+        };
 
         Self {
             x_vals: x_vals,
             dataset_path:dataset_path,
-            method: CorrelationMethod::pearson
+            method: method
         }
 
     }
 
     fn compute(){
 
+        todo!()
+
         //where the magic happens
         //reading the file ?? should happen in new
         // compute for each pair()
@@ -162,8 +175,48 @@ impl <'a> Compute<'a>{
     }
 
 }
-
+#[derive(PartialEq,Debug)]
 enum CorrelationMethod {
-    pearson,
-    spearman
+    Pearson,
+    Spearman
+}
+
+
+
+#[cfg(test)]
+
+mod tests {
+
+
+    use super::*;
+    #[test]
+    fn test_compute_obj(){
+       let x_vals  = [1.,3.,4.,5.,6.,7.,7.];
+       let new_compute = [Compute::new("spearman", "./notes.txt", &x_vals), Compute::new("pearson", "./note2.txt", &x_vals)];
+
+
+       assert_eq!([Compute {
+        x_vals:&[1.,3.,4.,5.,6.,7.,7.],
+        dataset_path:"./notes.txt",
+        method:CorrelationMethod::Spearman
+    },Compute {
+        x_vals:&[1.,3.,4.,5.,6.,7.,7.],
+        dataset_path:"./note2.txt",
+        method:CorrelationMethod::Pearson
+    }],new_compute)
+
+
+    }
+
+    #[test]
+    #[should_panic]
+    fn test_compute_panics(){
+
+        let new_compute = Compute::new("unknown","/notes.txt",&[1.2,1.4,1.5]);
+        assert_eq!(new_compute,Compute{
+            x_vals:&[1.2,1.4,1.5],
+            dataset_path:"/notes.txt",
+            method:CorrelationMethod::Pearson
+        })
+    }
 }
\ No newline at end of file