forked from M-Labs/nalgebra
use tempdir to write matrix when running test
This commit is contained in:
parent
8e48d26767
commit
31fc498182
@ -34,6 +34,7 @@ pest_derive = { version = "2", optional = true }
|
||||
itertools = "0.10"
|
||||
matrixcompare = { version = "0.3.0", features = [ "proptest-support" ] }
|
||||
nalgebra = { version="0.30", path = "../", features = ["compare"] }
|
||||
tempfile = "3"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
# Enable certain features when building docs for docs.rs
|
||||
|
@ -1487,10 +1487,7 @@ pub fn write_to_matrix_market_str<T: MatrixMarketScalar, S: MatrixMarketExport<T
|
||||
/// 2 3 5
|
||||
/// "#;
|
||||
/// let matrix = load_coo_from_matrix_market_str::<i32>(&str).unwrap();
|
||||
/// // create a temporary file 'temp.mtx'
|
||||
/// let mut tempdir = std::env::temp_dir();
|
||||
/// tempdir.push("temp.mtx");
|
||||
/// write_to_matrix_market_file(&matrix,tempdir).unwrap();
|
||||
/// write_to_matrix_market_file(&matrix,"path/to/matrix.mtx").unwrap();
|
||||
/// ```
|
||||
pub fn write_to_matrix_market_file<
|
||||
T: MatrixMarketScalar,
|
||||
|
@ -8,6 +8,7 @@ use nalgebra_sparse::io::{
|
||||
use nalgebra_sparse::proptest::coo_no_duplicates;
|
||||
use nalgebra_sparse::CooMatrix;
|
||||
use proptest::prelude::*;
|
||||
use tempfile::tempdir;
|
||||
|
||||
type C64 = Complex<f64>;
|
||||
type C32 = Complex<f32>;
|
||||
@ -457,10 +458,11 @@ proptest! {
|
||||
proptest! {
|
||||
#[test]
|
||||
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();
|
||||
tempdir.push("temp.mtx");
|
||||
write_to_matrix_market_file(&coo,&tempdir).unwrap();
|
||||
let generated_matrix = load_coo_from_matrix_market_file(tempdir).unwrap();
|
||||
let temp_dir = tempdir().expect("Unable to create temporary directory");
|
||||
let file_path = temp_dir.path().join("temp.mtx");
|
||||
write_to_matrix_market_file(&coo,&file_path).unwrap();
|
||||
let generated_matrix = load_coo_from_matrix_market_file(file_path).unwrap();
|
||||
assert_matrix_eq!(generated_matrix, coo);
|
||||
temp_dir.close().expect("Unable to delete temporary directory");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user