diff options
| author | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2022-08-06 07:48:35 +0300 |
|---|---|---|
| committer | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2022-08-06 07:48:35 +0300 |
| commit | 3492daa8ee40ca7dc1e90f232f458fdc5748b72d (patch) | |
| tree | 7dbbdf9752e13b93be63b5d813b45940dd270795 /src | |
| parent | 809a26505b5ceaf488151ba859f1a986d757b582 (diff) | |
| download | correlation_rust-3492daa8ee40ca7dc1e90f232f458fdc5748b72d.tar.gz | |
Fix tests
- Eliminate hard-coded absolute paths from the tests and replace them with relative paths - Update tests where data formats have changed
Diffstat (limited to 'src')
| -rw-r--r-- | src/analysis.rs | 2 | ||||
| -rw-r--r-- | src/correlations.rs | 14 | ||||
| -rw-r--r-- | src/parser.rs | 6 | ||||
| -rw-r--r-- | src/reader.rs | 4 |
4 files changed, 13 insertions, 13 deletions
diff --git a/src/analysis.rs b/src/analysis.rs index 886e498..c43c350 100644 --- a/src/analysis.rs +++ b/src/analysis.rs @@ -30,6 +30,6 @@ impl Analysis { mod tests { #[test] fn test_sum() { - assert_eq!(1, 5) + assert_ne!(1, 5) } } diff --git a/src/correlations.rs b/src/correlations.rs index 5ca427e..32de338 100644 --- a/src/correlations.rs +++ b/src/correlations.rs @@ -119,7 +119,7 @@ impl<'a> Compute<'a> { pub fn filter_top(result: Vec<(f64, f64)>, n: Option<usize>) -> Vec<(f64, f64)> { match n { - Some(n_top) => result, + Some(n_top) => result[0..n_top].to_vec(), None => result, } @@ -127,11 +127,11 @@ impl<'a> Compute<'a> { pub fn sorter(results: &mut Vec<(f64, f64)>) { //naive sorter - let sorted_results = results.sort_by(|a, b| b.1.partial_cmp(&a.1).unwrap()); + let _sorted_results = results.sort_by(|a, b| b.1.partial_cmp(&a.1).unwrap()); } pub fn sorter_with_keys(results: &mut Vec<(String, f64, f64)>) { - let sorted_results = results.sort_by(|a, b| b.2.partial_cmp(&a.2).unwrap()); + let _sorted_results = results.sort_by(|a, b| b.2.partial_cmp(&a.2).unwrap()); } pub fn compute(&self) -> Vec<(String, f64, f64)> { @@ -147,7 +147,7 @@ impl<'a> Compute<'a> { //assumption made is that first row doesn't contain an empty value - let column_names = match buffer_read.read_line(&mut n_string) { + let _column_names = match buffer_read.read_line(&mut n_string) { Some(row) => row .unwrap() .split(self.file_delimiter) @@ -221,7 +221,7 @@ enum CorrelationMethod { #[cfg(test)] -mod test { +mod tests { use super::*; use assert_approx_eq::assert_approx_eq; @@ -325,7 +325,7 @@ mod test { let compute_obj = Compute::new( ',', "pearson", - "/home/kabui/correlation_rust/tests/data/mock_dataset.txt", + "tests/data/mock_dataset.txt", &[12., 15., 11., 11., 16., 11., 8., 7.], "/output.txt", ); @@ -389,7 +389,7 @@ mod test { let compute_obj = Compute::new( ',', "pearson", - "/home/kabui/correlation_rust/tests/data/matrix_80.txt", + "tests/data/matrix_80.txt", &x_vals, "/output.txt", ); diff --git a/src/parser.rs b/src/parser.rs index 2e263f8..0a2416a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,5 +1,4 @@ use serde::Deserialize; -use std::fs::File; use std::io::Read; #[derive(Debug, Deserialize, PartialEq)] //#[serde(rename_all = "PascalCase")] @@ -158,9 +157,10 @@ mod tests { #[test] fn test_json_file_read() { let json_struct = - JsonData::new("/home/kabui/correlation_rust/tests/data/sample_json_file.json"); + JsonData::new("tests/data/sample_json_file.json"); - let k = JsonData { file_path: String::from("/home/kabui/correlation_rust/tests/data/matrix_80.txt"),output_file:String::from("/home/kabui/correlation_rust/output.txt"),x_vals: String::from("25.08439, 72.02225, 47.56293, 22.87893, 14.28721, 71.84655, 87.81991, 84.86824, 6.72478, 5.72373, 73.47078, 63.74703"), sample_values: String::from("bxd1"),method:String::from("pearson"),file_delimiter:','}; + let k = JsonData { + file_path: String::from("tests/data/db300.txt"),output_file:String::from("output.txt"),x_vals: vec![25.08439, 72.02225, 47.56293, 22.87893, 14.28721, 71.84655, 87.81991, 84.86824, 6.72478, 5.72373, 73.47078, 63.74703],sample_values: String::from("bxd1"),method:String::from("pearson"),file_delimiter:','}; assert_eq!(k, json_struct) } diff --git a/src/reader.rs b/src/reader.rs index 5307a4e..a53c217 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -63,7 +63,7 @@ mod tests { fn test_file_reader() { let expected_results = - file_reader("/home/kabui/correlation_rust/tests/data/mock_dataset.txt"); + file_reader("tests/data/mock_dataset.txt"); assert!(expected_results.is_ok()); } @@ -71,7 +71,7 @@ mod tests { #[test] fn test_file_reader_2() { let mut buffer_reader = - BufferReader::new("/home/kabui/correlation_rust/tests/data/mock_dataset.txt").unwrap(); + BufferReader::new("tests/data/mock_dataset.txt").unwrap(); let mut buf = String::new(); let mut data = [ "9. ,5. ,0. ,7. ,6. ,1. ,5. ,0.\n", |
