LCOV - code coverage report
Current view: top level - test - CartesianTest.cc (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 96 100 96.0 %
Date: 2016-06-29 12:30:40 Functions: 22 22 100.0 %

          Line data    Source code
       1             : #include <libdash.h>
       2             : #include <array>
       3             : #include <numeric>
       4             : #include <functional>
       5             : #include "TestBase.h"
       6             : #include "CartesianTest.h"
       7             : 
       8          20 : TEST_F(CartesianTest, DefaultConstructor) {
       9           4 :   DASH_TEST_LOCAL_ONLY();
      10             :   // 1-dimensional:
      11           1 :   dash::CartesianIndexSpace<1> cartesian1d;
      12           1 :   EXPECT_EQ(cartesian1d.size(), 0);
      13           1 :   EXPECT_EQ(cartesian1d.rank(), 1);
      14           1 :   EXPECT_EQ(cartesian1d.extent(0), 0);
      15             : #if defined(DASH_ENABLE_ASSERTIONS)
      16           2 :   EXPECT_THROW(
      17             :     cartesian1d.at(0),
      18           0 :     dash::exception::OutOfRange);
      19           2 :   EXPECT_THROW(
      20             :     cartesian1d.coords(0),
      21           0 :     dash::exception::OutOfRange);
      22             : #endif
      23             :   // 4-dimensional:
      24           1 :   dash::CartesianIndexSpace<4> cartesian4d;
      25           1 :   EXPECT_EQ(cartesian4d.size(), 0);
      26           1 :   EXPECT_EQ(cartesian4d.rank(), 4);
      27           1 :   EXPECT_EQ(cartesian4d.extent(0), 0);
      28           1 :   EXPECT_EQ(cartesian4d.extent(1), 0);
      29           1 :   EXPECT_EQ(cartesian4d.extent(2), 0);
      30           1 :   EXPECT_EQ(cartesian4d.extent(3), 0);
      31             : #if defined(DASH_ENABLE_ASSERTIONS)
      32           2 :   EXPECT_THROW(
      33             :     cartesian4d.at(0, 0, 0, 0),
      34           0 :     dash::exception::OutOfRange);
      35           2 :   EXPECT_THROW(
      36             :     cartesian4d.coords(0),
      37           0 :     dash::exception::OutOfRange);
      38             : #endif
      39             : }
      40             : 
      41          20 : TEST_F(CartesianTest, Conversion1Dim) {
      42           4 :   DASH_TEST_LOCAL_ONLY();
      43           1 :   int extent = 42;
      44           1 :   dash::CartesianIndexSpace<1> cartesian1d(extent);
      45           1 :   EXPECT_EQ(cartesian1d.rank(), 1);
      46           1 :   EXPECT_EQ(cartesian1d.size(), extent);
      47           1 :   EXPECT_EQ(cartesian1d.extent(0), extent);
      48          43 :   for (size_t i = 0; i < extent; ++i) {
      49          42 :     EXPECT_EQ(cartesian1d.at(i), i);
      50          42 :     EXPECT_EQ(cartesian1d.coords(i)[0], i);
      51             :   }
      52             : }
      53             : 
      54          20 : TEST_F(CartesianTest, Conversion2Dim) {
      55           4 :   DASH_TEST_LOCAL_ONLY();
      56           1 :   int extent_x = 3;
      57           1 :   int extent_y = 5;
      58             :   dash::CartesianIndexSpace<2, dash::ROW_MAJOR, size_t> cartesian2dR(
      59           1 :     extent_x, extent_y);
      60             :   dash::CartesianIndexSpace<2, dash::COL_MAJOR, size_t> cartesian2dC(
      61           1 :     extent_x, extent_y);
      62           1 :   EXPECT_EQ(cartesian2dR.rank(), 2);
      63           1 :   EXPECT_EQ(cartesian2dC.rank(), 2);
      64           1 :   EXPECT_EQ(cartesian2dR.size(), extent_x * extent_y);
      65           1 :   EXPECT_EQ(cartesian2dC.size(), extent_x * extent_y);
      66           1 :   EXPECT_EQ(cartesian2dR.extent(0), extent_x);
      67           1 :   EXPECT_EQ(cartesian2dR.extent(0), extent_x);
      68           1 :   EXPECT_EQ(cartesian2dC.extent(1), extent_y);
      69           1 :   EXPECT_EQ(cartesian2dC.extent(1), extent_y);
      70           4 :   for (size_t x = 0; x < extent_x; ++x) {
      71          18 :     for (size_t y = 0; y < extent_y; ++y) {
      72          15 :       size_t exp_index_col_major = (y * extent_x) + x;
      73          15 :       size_t exp_index_row_major = (x * extent_y) + y;
      74          15 :       EXPECT_EQ(exp_index_row_major, cartesian2dR.at(x, y));
      75          15 :       EXPECT_EQ(x, cartesian2dR.coords(exp_index_row_major)[0]);
      76          15 :       EXPECT_EQ(y, cartesian2dR.coords(exp_index_row_major)[1]);
      77          15 :       EXPECT_EQ(exp_index_col_major, cartesian2dC.at(x, y));
      78          15 :       EXPECT_EQ(x, cartesian2dC.coords(exp_index_col_major)[0]);
      79          15 :       EXPECT_EQ(y, cartesian2dC.coords(exp_index_col_major)[1]);
      80             :     }
      81             :   }
      82             : }
      83             : 
      84          20 : TEST_F(CartesianTest, Conversion3Dim) {
      85           7 :   DASH_TEST_LOCAL_ONLY();
      86           1 :   int extent_x = 5;
      87           1 :   int extent_y = 7;
      88           1 :   int extent_z = 11;
      89           1 :   size_t size  = extent_x * extent_y * extent_z;
      90             :   dash::CartesianIndexSpace<3, dash::ROW_MAJOR, size_t> cartesian3dR(
      91           1 :     extent_x, extent_y, extent_z);
      92             :   dash::CartesianIndexSpace<3, dash::COL_MAJOR, size_t> cartesian3dC(
      93           1 :     extent_x, extent_y, extent_z);
      94           1 :   ASSERT_EQ(cartesian3dR.rank(), 3);
      95           1 :   ASSERT_EQ(cartesian3dC.rank(), 3);
      96           1 :   ASSERT_EQ(cartesian3dR.size(), size);
      97           1 :   ASSERT_EQ(cartesian3dC.size(), size);
      98           1 :   ASSERT_EQ(cartesian3dR.extent(0), extent_x);
      99           1 :   ASSERT_EQ(cartesian3dR.extent(0), extent_x);
     100           1 :   ASSERT_EQ(cartesian3dC.extent(1), extent_y);
     101           1 :   ASSERT_EQ(cartesian3dC.extent(1), extent_y);
     102           1 :   ASSERT_EQ(cartesian3dC.extent(2), extent_z);
     103           1 :   ASSERT_EQ(cartesian3dC.extent(2), extent_z);
     104           6 :   for (size_t x = 0; x < extent_x; ++x) {
     105          40 :     for (size_t y = 0; y < extent_y; ++y) {
     106         420 :       for (size_t z = 0; z < extent_z; ++z) {
     107             :         size_t exp_index_col_major =
     108         385 :           (z * extent_x * extent_y) + (y * extent_x) + x;
     109             :         size_t exp_index_row_major =
     110         385 :           (x * extent_y * extent_z) + (y * extent_z) + z;
     111         385 :         ASSERT_EQ(exp_index_row_major, cartesian3dR.at(x, y, z));
     112         385 :         ASSERT_EQ(x, cartesian3dR.coords(exp_index_row_major)[0]);
     113         385 :         ASSERT_EQ(y, cartesian3dR.coords(exp_index_row_major)[1]);
     114         385 :         ASSERT_EQ(exp_index_col_major, cartesian3dC.at(x, y, z));
     115         385 :         ASSERT_EQ(x, cartesian3dC.coords(exp_index_col_major)[0]);
     116         385 :         ASSERT_EQ(y, cartesian3dC.coords(exp_index_col_major)[1]);
     117             :       }
     118             :     }
     119             :   }
     120             : }
     121             : 
     122          20 : TEST_F(CartesianTest, Conversion10Dim) {
     123           4 :   DASH_TEST_LOCAL_ONLY();
     124           1 :   const size_t Dimensions = 10;
     125             :   ::std::array<size_t, Dimensions> extents =
     126           1 :     { 3, 13, 17, 23, 2, 3, 1, 1, 2, 2 };
     127           2 :   size_t size = ::std::accumulate(extents.begin(), extents.end(), 1,
     128           1 :                                   ::std::multiplies<size_t>());
     129             :   dash::CartesianIndexSpace<Dimensions, dash::ROW_MAJOR, size_t>
     130           1 :     cartesianR(extents);
     131             :   dash::CartesianIndexSpace<Dimensions, dash::COL_MAJOR, size_t>
     132           1 :     cartesianC(extents);
     133           1 :   EXPECT_EQ(cartesianR.rank(), Dimensions);
     134           1 :   EXPECT_EQ(cartesianC.rank(), Dimensions);
     135           1 :   EXPECT_EQ(cartesianR.size(), size);
     136           1 :   EXPECT_EQ(cartesianC.size(), size);
     137          11 :   for (int d = 0; d < Dimensions; ++d) {
     138          10 :     EXPECT_EQ(cartesianR.extent(d), extents[d]);
     139          10 :     EXPECT_EQ(cartesianC.extent(d), extents[d]);
     140             :   }
     141          12 : }
     142             : 

Generated by: LCOV version 1.12