示例#1
0
void __TestReorderCopy()
{
    size_t numTuples = 10;
    QVector<size_t> cDims(1, 5);
    QString name("Source Array");

    //make sure that an incorrectly sized order returns a null pointer
    typename DataArray<T>::Pointer src = DataArray<T>::CreateArray(numTuples, cDims, name, false);
    QVector<size_t> wrongSize(numTuples + 1);
    typename DataArray<T>::Pointer copy = boost::dynamic_pointer_cast<DataArray<T> >(src->reorderCopy(wrongSize));
    DREAM3D_REQUIRE_EQUAL(copy.get(), 0);

    // fill reorder vector with same index (using this would be the same result as deep copy)
    QVector<size_t> newOrder(numTuples);
    for(size_t i = 0; i < numTuples; i++)
    {
        newOrder[i] = i;
    }

    //shuffle order
    std::random_shuffle(newOrder.begin(), newOrder.end());

    // First lets try it without allocating any memory
    copy = boost::dynamic_pointer_cast<DataArray<T> >(src->reorderCopy(newOrder));

    //if newOrder is inporperly size a null pointer is returned
    DREAM3D_REQUIRE_NE(copy.get(), 0);

    //check sizes
    DREAM3D_REQUIRED(copy->getNumberOfTuples(), ==, src->getNumberOfTuples() );
    DREAM3D_REQUIRED(copy->isAllocated(), ==, src->isAllocated() );

    // Create the array again, this time allocating the data and putting in some known data
    src = DataArray<T>::CreateArray(numTuples, cDims, name, true);
    for(size_t i = 0; i < src->getSize(); i++)
    {
        src->setValue(i, i);
    }

    for(size_t i = 0; i < numTuples; i++)
    {
        for(size_t j = 0; j < cDims[0]; j++)
        {
            src->setComponent(i, j, static_cast<T>(i * cDims[0] + j) );
        }
    }
    copy = boost::dynamic_pointer_cast<DataArray<T> >(src->reorderCopy(newOrder));
    for(size_t i = 0; i < numTuples; i++)
    {
        for(size_t j = 0; j < cDims[0]; j++)
        {
            T cpy = copy->getComponent(newOrder[i], j);
            T val = src->getComponent(i, j);
            DREAM3D_REQUIRE_EQUAL(cpy, val)
        }
    }
}
示例#2
0
  void __TestNeighborList()
  {
    typename NeighborList<T>::Pointer n = NeighborList<T>::New();
    n->setName("Test");

    for(int i = 0; i < 4; ++i)
    {
      for(T j = 0; j < (T)(i + 4); ++j)
      {
        n->addEntry(i, static_cast<T>(j * i + 3) );
      }
    }

    typename NeighborList<T>::SharedVectorType v;
    for(int i = 0; i < 4; ++i)
    {
      v = n->getList(i);
      DREAM3D_REQUIRE_NE(v.get(), 0);
    }

    // Remove the front 2 elements and test
    QVector<size_t> eraseElements;
    eraseElements.push_back(0);
    eraseElements.push_back(1);

    n->eraseTuples(eraseElements);
    for(int i = 0; i < 2; ++i)
    {
      v = n->getList(i);
      DREAM3D_REQUIRE_NE(v.get(), 0);
      DREAM3D_REQUIRE_EQUAL(v->size(), static_cast<size_t>(i + 2 + 4) );
      for(T j = 0; j < (T)(i + 4 + 2); ++j)
      {
        DREAM3D_REQUIRE_EQUAL(v->at(j), j * (i + 2) + 3);
      }
    }

    // Reset and erase the back 2 "Tuples"
    n->clearAllLists();
    for(int i = 0; i < 4; ++i)
    {
      for(T j = 0; j < (T)(i + 4); ++j)
      {
        n->addEntry(i, j * i + 3);
      }
    }
    eraseElements.clear();
    eraseElements.push_back(2);
    eraseElements.push_back(3);
    n->eraseTuples(eraseElements);
    for(int i = 0; i < 2; ++i)
    {
      v = n->getList(i);
      DREAM3D_REQUIRE_NE(v.get(), 0);
      DREAM3D_REQUIRE_EQUAL(v->size(), static_cast<size_t>(i + 4) );
      for(T j = 0; j < (T)(i + 4); ++j)
      {
        DREAM3D_REQUIRE_EQUAL(v->at(j), j * i + 3);
      }
    }

    // Reset and erase the back 2 "Tuples"
    n->clearAllLists();
    for(int i = 0; i < 4; ++i)
    {
      for(T j = 0; j < (T)(i + 4); ++j)
      {
        n->addEntry(i, j * i + 3);
      }
    }
    eraseElements.clear();
    eraseElements.push_back(1);
    eraseElements.push_back(2);
    n->eraseTuples(eraseElements);
    int i = 0;
    v = n->getList(i);
    DREAM3D_REQUIRE_NE(v.get(), 0);
    DREAM3D_REQUIRE_EQUAL(v->size(), static_cast<size_t>(i + 4) );
    for(T j = 0; j < (T)(i + 4); ++j)
    {
      DREAM3D_REQUIRE_EQUAL(v->at(j), j * i + 3);
    }
    i = 1;
    v = n->getList(i);
    DREAM3D_REQUIRE_NE(v.get(), 0);
    i = 3;
    DREAM3D_REQUIRE_EQUAL(v->size(), static_cast<size_t>(i + 4) );
    for(T j = 0; j < (T)(i + 4); ++j)
    {
      DREAM3D_REQUIRE_EQUAL(v->at(j), j * i + 3);
    }
  }