MyraMath
bounds_SparseMatrix


Source: tests/sparse/bounds_SparseMatrix.cpp

1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
11 // Containers.
13 
14 // Reporting.
15 #include <tests/myratest.h>
16 
17 using namespace myra;
18 
19 ADD_TEST("bounds_SparseMatrix","[sparse]")
20  {
21  // Make random A, access it out of bounds in a variety of ways.
22  auto A = SparseMatrix<double>::random(3,3,4);
23  // Scalar access using at()
24  REQUIRE_EXCEPTION( auto a = A.at(3,0); );
25  REQUIRE_EXCEPTION( auto a = A.at(0,3); );
26  REQUIRE_EXCEPTION( auto a = A.at(-1,0); );
27  REQUIRE_EXCEPTION( auto a = A.at(0,-1); );
28  // Window access along i.
29  REQUIRE_EXCEPTION( auto a = A.rows(0,4); );
30  REQUIRE_EXCEPTION( auto a = A.rows(4,7); );
31  REQUIRE_EXCEPTION( auto a = A.rows(-1,1); );
32  REQUIRE_EXCEPTION( auto a = A.rows(2,-1); );
33  REQUIRE_EXCEPTION( auto a = A.rows(2,1); );
34  // Window access along j.
35  REQUIRE_EXCEPTION( auto a = A.columns(0,4); );
36  REQUIRE_EXCEPTION( auto a = A.columns(4,7); );
37  REQUIRE_EXCEPTION( auto a = A.columns(-1,1); );
38  REQUIRE_EXCEPTION( auto a = A.columns(2,-1); );
39  REQUIRE_EXCEPTION( auto a = A.columns(2,1); );
40  // Checking at(), where the (i,j) is in bounds but maps to a structural zero.
42  REQUIRE_EXCEPTION( auto i = I.at(0,1); );
43  // Checking A.iterator == B.iterator
44  auto B = A;
45  REQUIRE_EXCEPTION( bool flag = A.begin() == B.begin(); );
46  }
static SparseMatrix< Number > random(int I, int J, int N)
Generates a random SparseMatrix with size IxJ and (approximately) N nonzeros.
Definition: SparseMatrix.cpp:493
General purpose compressed-sparse-column (CSC) container.
Definition: syntax.dox:1
static SparseMatrix< Number > identity(int IJ)
Generates an identity SparseMatrix of specified size.
Definition: SparseMatrix.cpp:481


Results: [PASS]


Go back to Summary of /test programs.