use tempdir to write matrix when running test

This commit is contained in:
Hantao Hui 2022-05-07 13:40:25 +02:00
parent 8e48d26767
commit 31fc498182
3 changed files with 8 additions and 8 deletions

View File

@ -34,6 +34,7 @@ pest_derive = { version = "2", optional = true }
itertools = "0.10" itertools = "0.10"
matrixcompare = { version = "0.3.0", features = [ "proptest-support" ] } matrixcompare = { version = "0.3.0", features = [ "proptest-support" ] }
nalgebra = { version="0.30", path = "../", features = ["compare"] } nalgebra = { version="0.30", path = "../", features = ["compare"] }
tempfile = "3"
[package.metadata.docs.rs] [package.metadata.docs.rs]
# Enable certain features when building docs for docs.rs # Enable certain features when building docs for docs.rs

View File

@ -1487,10 +1487,7 @@ pub fn write_to_matrix_market_str<T: MatrixMarketScalar, S: MatrixMarketExport<T
/// 2 3 5 /// 2 3 5
/// "#; /// "#;
/// let matrix = load_coo_from_matrix_market_str::<i32>(&str).unwrap(); /// let matrix = load_coo_from_matrix_market_str::<i32>(&str).unwrap();
/// // create a temporary file 'temp.mtx' /// write_to_matrix_market_file(&matrix,"path/to/matrix.mtx").unwrap();
/// let mut tempdir = std::env::temp_dir();
/// tempdir.push("temp.mtx");
/// write_to_matrix_market_file(&matrix,tempdir).unwrap();
/// ``` /// ```
pub fn write_to_matrix_market_file< pub fn write_to_matrix_market_file<
T: MatrixMarketScalar, T: MatrixMarketScalar,

View File

@ -8,6 +8,7 @@ use nalgebra_sparse::io::{
use nalgebra_sparse::proptest::coo_no_duplicates; use nalgebra_sparse::proptest::coo_no_duplicates;
use nalgebra_sparse::CooMatrix; use nalgebra_sparse::CooMatrix;
use proptest::prelude::*; use proptest::prelude::*;
use tempfile::tempdir;
type C64 = Complex<f64>; type C64 = Complex<f64>;
type C32 = Complex<f32>; type C32 = Complex<f32>;
@ -457,10 +458,11 @@ proptest! {
proptest! { proptest! {
#[test] #[test]
fn coo_matrix_market_roundtrip_file(coo in coo_no_duplicates(-10 ..= 10, 0 ..= 10, 0..= 10, 100)) { fn coo_matrix_market_roundtrip_file(coo in coo_no_duplicates(-10 ..= 10, 0 ..= 10, 0..= 10, 100)) {
let mut tempdir = std::env::temp_dir(); let temp_dir = tempdir().expect("Unable to create temporary directory");
tempdir.push("temp.mtx"); let file_path = temp_dir.path().join("temp.mtx");
write_to_matrix_market_file(&coo,&tempdir).unwrap(); write_to_matrix_market_file(&coo,&file_path).unwrap();
let generated_matrix = load_coo_from_matrix_market_file(tempdir).unwrap(); let generated_matrix = load_coo_from_matrix_market_file(file_path).unwrap();
assert_matrix_eq!(generated_matrix, coo); assert_matrix_eq!(generated_matrix, coo);
temp_dir.close().expect("Unable to delete temporary directory");
} }
} }