From d79dead1aa74742dd7387fe33d795de69e2cacf5 Mon Sep 17 00:00:00 2001 From: Lukas Cejka <lukas.ostatek@gmail.com> Date: Sun, 4 Nov 2018 16:16:24 +0100 Subject: [PATCH] Added test for setCompressedRowLengths function. This test is correct assuming that getRowLength() works correctly and doesn't need to be tested. --- src/UnitTests/Matrices/SparseMatrixTest.h | 44 ++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/UnitTests/Matrices/SparseMatrixTest.h b/src/UnitTests/Matrices/SparseMatrixTest.h index f1f4bad246..74a03fd3b4 100644 --- a/src/UnitTests/Matrices/SparseMatrixTest.h +++ b/src/UnitTests/Matrices/SparseMatrixTest.h @@ -58,6 +58,36 @@ void testSetDimensions() EXPECT_EQ( m.getColumns(), 8); } +template< typename Matrix > +void testSetCompressedRowLengths() +{ + Matrix m; + const int rows = 10; + const int cols = 11; + + m.reset(); + m.setDimensions( rows, cols ); + typename Matrix::CompressedRowLengthsVector rowLengths; + rowLengths.setSize( rows ); + rowLengths.setValue( 3 ); + int value = 1; + for (int i = 2; i < rows; i++) + rowLengths.setElement( i, value++ ); + + m.setCompressedRowLengths( rowLengths ); + + EXPECT_EQ( m.getRowLength( 0), 3 ); + EXPECT_EQ( m.getRowLength( 1), 3 ); + EXPECT_EQ( m.getRowLength( 2), 1 ); + EXPECT_EQ( m.getRowLength( 3), 2 ); + EXPECT_EQ( m.getRowLength( 4), 3 ); + EXPECT_EQ( m.getRowLength( 5), 4 ); + EXPECT_EQ( m.getRowLength( 6), 5 ); + EXPECT_EQ( m.getRowLength( 7), 6 ); + EXPECT_EQ( m.getRowLength( 8), 7 ); + EXPECT_EQ( m.getRowLength( 9), 8 ); +} + TEST( SparseMatrixTest, CSR_GetTypeTest_Host ) { host_testGetType< CSR_host_float, CSR_host_int >(); @@ -70,7 +100,7 @@ TEST( SparseMatrixTest, CSR_GetTypeTest_Cuda ) } #endif -TEST( SparseMatrixTest, CSR_testSetDimensions_Host ) +TEST( SparseMatrixTest, CSR_SetDimensionsTest_Host ) { testSetDimensions< CSR_host_int >(); } @@ -82,6 +112,18 @@ TEST( SparseMatrixTest, CSR_SetDimensionsTest_Cuda ) } #endif +TEST( SparseMatrixTest, CSR_setCompressedRowLengthsTest_Host ) +{ + testSetCompressedRowLengths< CSR_host_int >(); +} + +#ifdef HAVE_CUDA +TEST( SparseMatrixTest, CSR_setCompressedRowLengthsTest_Cuda ) +{ + testSetCompressedRowLengths< CSR_cuda_int >(); +} +#endif + #endif #include "../GtestMissingError.h" -- GitLab