Ignore:
Timestamp:
Jun 9, 2016, 5:55:43 AM (9 years ago)
Author:
Frederik Heber <heber@…>
Children:
52ecd0
Parents:
6c0b3f
git-author:
Frederik Heber <heber@…> (05/26/16 15:36:26)
git-committer:
Frederik Heber <heber@…> (06/09/16 05:55:43)
Message:

Added padWithZerosForEvenNumberedSamples(), required by downsample().

  • added unit test function.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Summation/SetValues/unittests/SamplingGridUnitTest.cpp

    r6c0b3f r26f238  
    581581      returnthreshold *= third_two;
    582582  return returnthreshold;
     583}
     584
     585/** UnitTest for padWithZerosForEvenNumberedSamples()
     586 *
     587 */
     588void SamplingGridTest::padWithZerosForEvenNumberedSamplesTest()
     589{
     590  const double begin[NDIM] = { 0., 0., 0. };
     591  const double end[NDIM] = { 2., 2., 2. };
     592
     593  // we check for window of odd numbers
     594  {
     595  //    LOG(2, "Checking with difference " << grid_difference);
     596    const int gridpoints = 1*2*2;
     597    const int extended_gridpoints = 2*4*4;
     598    SamplingGrid::sampledvalues_t values(gridpoints, 1.); // length in one axis is odd
     599    SamplingGrid::sampledvalues_t checkvalues(extended_gridpoints, 0.);
     600    {
     601      int N[NDIM];
     602      int index = 0;
     603      for (N[0]=2;N[0]<3;++N[0]) {
     604        for (N[1]=0;N[1]<1;++N[1]) {
     605          for (N[2]=0;N[2]<4;++N[2]) {
     606            checkvalues[index++] = 0.;
     607          }
     608        }
     609        for (N[1]=1;N[1]<3;++N[1]) {
     610          checkvalues[index++] = 0.;
     611          for (N[2]=1;N[2]<3;++N[2]) {
     612            checkvalues[index++] = 1.;
     613          }
     614          checkvalues[index++] = 0.;
     615        }
     616        for (N[1]=3;N[1]<4;++N[1]) {
     617          for (N[2]=0;N[2]<4;++N[2]) {
     618            checkvalues[index++] = 0.;
     619          }
     620        }
     621      }
     622      for (N[0]=3;N[0]<4;++N[0]) {
     623        for (N[1]=0;N[1]<4;++N[1]) {
     624          for (N[2]=0;N[2]<4;++N[2]) {
     625            checkvalues[index++] = 0.;
     626          }
     627        }
     628      }
     629    }
     630
     631    /** Here, we must initialize the larger grid with zero window first and
     632     * then add the values into the smaller window.
     633     */
     634    SamplingGrid grid(begin, end, 2);
     635    const double window_begin[NDIM] = {
     636        grid.getNearestHigherGridPoint(1.0, 0), // index 2
     637        grid.getNearestHigherGridPoint(0.5, 1), // index 1 -> 0
     638        grid.getNearestHigherGridPoint(0.5, 2) }; // index 1 -> 0
     639    const double window_end[NDIM] = {
     640        grid.getNearestLowerGridPoint(1.5, 0), // index 3 -> 4
     641        grid.getNearestLowerGridPoint(1.5, 1), // index 3 -> 4
     642        grid.getNearestLowerGridPoint(1.5, 2) }; // index 3 -> 4
     643    grid.setWindow(window_begin, window_end);
     644    grid.addOntoWindow(window_begin, window_end, values, +1.);
     645    grid.padWithZerosForEvenNumberedSamples();
     646
     647    SamplingGrid checkgrid(begin, end, 2);
     648    const double check_window_begin[NDIM] = {
     649        checkgrid.getNearestHigherGridPoint(1., 0),
     650        checkgrid.getNearestHigherGridPoint(0., 1),
     651        checkgrid.getNearestHigherGridPoint(0., 2) };
     652    const double check_window_end[NDIM] = {
     653        checkgrid.getNearestHigherGridPoint(2., 0),
     654        checkgrid.getNearestHigherGridPoint(2., 1),
     655        checkgrid.getNearestHigherGridPoint(2., 2) };
     656    checkgrid.setWindow(check_window_begin, check_window_end);
     657    checkgrid.addOntoWindow(check_window_begin, check_window_end, checkvalues, +1.);
     658
     659    std::cout << " grid value " << grid.sampled_grid << std::endl;
     660    std::cout << " checkgrid value " << checkgrid.sampled_grid << std::endl;
     661    CPPUNIT_ASSERT_EQUAL( checkgrid.sampled_grid.size(), grid.sampled_grid.size());
     662    CPPUNIT_ASSERT_EQUAL( checkgrid, grid );
     663  }
    583664}
    584665
Note: See TracChangeset for help on using the changeset viewer.