From 0936c4fad9f59749ec1d99cab8f4b04e1b0d81b8 Mon Sep 17 00:00:00 2001 From: Andreas Longva Date: Mon, 1 Feb 2021 08:52:13 +0100 Subject: [PATCH] Add tests for Csr/CscMatrix::identity --- nalgebra-sparse/tests/unit_tests/csc.rs | 7 +++++++ nalgebra-sparse/tests/unit_tests/csr.rs | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/nalgebra-sparse/tests/unit_tests/csc.rs b/nalgebra-sparse/tests/unit_tests/csc.rs index b27f19be..534adb4f 100644 --- a/nalgebra-sparse/tests/unit_tests/csc.rs +++ b/nalgebra-sparse/tests/unit_tests/csc.rs @@ -375,4 +375,11 @@ proptest! { prop_assert_eq!(d_entries, csc_diagonal_entries); } + + #[test] + fn csc_identity(n in 0 ..= 6usize) { + let csc = CscMatrix::::identity(n); + prop_assert_eq!(csc.nnz(), n); + prop_assert_eq!(DMatrix::from(&csc), DMatrix::identity(n, n)); + } } diff --git a/nalgebra-sparse/tests/unit_tests/csr.rs b/nalgebra-sparse/tests/unit_tests/csr.rs index 2de93e51..d1e62bed 100644 --- a/nalgebra-sparse/tests/unit_tests/csr.rs +++ b/nalgebra-sparse/tests/unit_tests/csr.rs @@ -375,4 +375,11 @@ proptest! { prop_assert_eq!(d_entries, csr_diagonal_entries); } + + #[test] + fn csr_identity(n in 0 ..= 6usize) { + let csr = CsrMatrix::::identity(n); + prop_assert_eq!(csr.nnz(), n); + prop_assert_eq!(DMatrix::from(&csr), DMatrix::identity(n, n)); + } }