| 13 | #include "random_without_cast_overflow.h" |
| 14 | |
| 15 | template<typename MatrixType> void basicStuff(const MatrixType& m) |
| 16 | { |
| 17 | typedef typename MatrixType::Scalar Scalar; |
| 18 | typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType; |
| 19 | typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType; |
| 20 | |
| 21 | Index rows = m.rows(); |
| 22 | Index cols = m.cols(); |
| 23 | |
| 24 | // this test relies a lot on Random.h, and there's not much more that we can do |
| 25 | // to test it, hence I consider that we will have tested Random.h |
| 26 | MatrixType m1 = MatrixType::Random(rows, cols), |
| 27 | m2 = MatrixType::Random(rows, cols), |
| 28 | m3(rows, cols), |
| 29 | mzero = MatrixType::Zero(rows, cols), |
| 30 | square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>::Random(rows, rows); |
| 31 | VectorType v1 = VectorType::Random(rows), |
| 32 | vzero = VectorType::Zero(rows); |
| 33 | SquareMatrixType sm1 = SquareMatrixType::Random(rows,rows), sm2(rows,rows); |
| 34 | |
| 35 | Scalar x = 0; |
| 36 | while(x == Scalar(0)) x = internal::random<Scalar>(); |
| 37 | |
| 38 | Index r = internal::random<Index>(0, rows-1), |
| 39 | c = internal::random<Index>(0, cols-1); |
| 40 | |
| 41 | m1.coeffRef(r,c) = x; |
| 42 | VERIFY_IS_APPROX(x, m1.coeff(r,c)); |
| 43 | m1(r,c) = x; |
| 44 | VERIFY_IS_APPROX(x, m1(r,c)); |
| 45 | v1.coeffRef(r) = x; |
| 46 | VERIFY_IS_APPROX(x, v1.coeff(r)); |
| 47 | v1(r) = x; |
| 48 | VERIFY_IS_APPROX(x, v1(r)); |
| 49 | v1[r] = x; |
| 50 | VERIFY_IS_APPROX(x, v1[r]); |
| 51 | |
| 52 | // test fetching with various index types. |
| 53 | Index r1 = internal::random<Index>(0, numext::mini(Index(127),rows-1)); |
| 54 | x = v1(static_cast<char>(r1)); |
| 55 | x = v1(static_cast<signed char>(r1)); |
| 56 | x = v1(static_cast<unsigned char>(r1)); |
| 57 | x = v1(static_cast<signed short>(r1)); |
| 58 | x = v1(static_cast<unsigned short>(r1)); |
| 59 | x = v1(static_cast<signed int>(r1)); |
| 60 | x = v1(static_cast<unsigned int>(r1)); |
| 61 | x = v1(static_cast<signed long>(r1)); |
| 62 | x = v1(static_cast<unsigned long>(r1)); |
| 63 | #if EIGEN_HAS_CXX11 |
| 64 | x = v1(static_cast<long long int>(r1)); |
| 65 | x = v1(static_cast<unsigned long long int>(r1)); |
| 66 | #endif |
| 67 | |
| 68 | VERIFY_IS_APPROX( v1, v1); |
| 69 | VERIFY_IS_NOT_APPROX( v1, 2*v1); |
| 70 | VERIFY_IS_MUCH_SMALLER_THAN( vzero, v1); |
| 71 | VERIFY_IS_MUCH_SMALLER_THAN( vzero, v1.squaredNorm()); |
| 72 | VERIFY_IS_NOT_MUCH_SMALLER_THAN(v1, v1); |
no test coverage detected