From ef2de72b9afd00df2d2fdc59044dc8e2fbfee5c6 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 27 Apr 2022 20:30:50 +0300 Subject: unittest for creating correlation obj --- src/correlations.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 5 deletions(-) (limited to 'src') 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 -- cgit 1.4.1