Beispiel #1
0
BOOST_AUTO_TEST_CASE_TEMPLATE (test_map_copy_constructor_1,
                               parameters, test_map_parameters)
{
  COMMON_MAP_TEST_SETUP;

  map_type  map1 (RANGE (value_data::values1 ()));
  map_type  map2 (RANGE (value_data::values2 ()));
  map_type  map3 (map1);
  map_type  map4 (map2);

  BOOST_CHECK_EQUAL (map3, map1);
  BOOST_CHECK_EQUAL (map4, map2);

  if (implementation::stable_order)
    {
      assert_identical_order (map3, keys_of (map1));
      assert_identical_order (map4, keys_of (map2));
    }
}
template<typename MatrixType> void map_class_matrix(const MatrixType& m)
{
  typedef typename MatrixType::Index Index;
  typedef typename MatrixType::Scalar Scalar;

  Index rows = m.rows(), cols = m.cols(), size = rows*cols;
  Scalar s1 = internal::random<Scalar>();

  // array1 and array2 -> aligned heap allocation
  Scalar* array1 = internal::aligned_new<Scalar>(size);
  for(int i = 0; i < size; i++) array1[i] = Scalar(1);
  Scalar* array2 = internal::aligned_new<Scalar>(size);
  for(int i = 0; i < size; i++) array2[i] = Scalar(1);
  // array3unaligned -> unaligned pointer to heap
  Scalar* array3 = new Scalar[size+1];
  for(int i = 0; i < size+1; i++) array3[i] = Scalar(1);
  Scalar* array3unaligned = internal::UIntPtr(array3)%EIGEN_MAX_ALIGN_BYTES == 0 ? array3+1 : array3;
  Scalar array4[256];
  if(size<=256)
    for(int i = 0; i < size; i++) array4[i] = Scalar(1);
  
  Map<MatrixType> map1(array1, rows, cols);
  Map<MatrixType, AlignedMax> map2(array2, rows, cols);
  Map<MatrixType> map3(array3unaligned, rows, cols);
  Map<MatrixType> map4(array4, rows, cols);
  
  VERIFY_IS_EQUAL(map1, MatrixType::Ones(rows,cols));
  VERIFY_IS_EQUAL(map2, MatrixType::Ones(rows,cols));
  VERIFY_IS_EQUAL(map3, MatrixType::Ones(rows,cols));
  map1 = MatrixType::Random(rows,cols);
  map2 = map1;
  map3 = map1;
  MatrixType ma1 = map1;
  MatrixType ma2 = map2;
  MatrixType ma3 = map3;
  VERIFY_IS_EQUAL(map1, map2);
  VERIFY_IS_EQUAL(map1, map3);
  VERIFY_IS_EQUAL(ma1, ma2);
  VERIFY_IS_EQUAL(ma1, ma3);
  VERIFY_IS_EQUAL(ma1, map3);
  
  VERIFY_IS_APPROX(s1*map1, s1*map2);
  VERIFY_IS_APPROX(s1*ma1, s1*ma2);
  VERIFY_IS_EQUAL(s1*ma1, s1*ma3);
  VERIFY_IS_APPROX(s1*map1, s1*map3);
  
  map2 *= s1;
  map3 *= s1;
  VERIFY_IS_APPROX(s1*map1, map2);
  VERIFY_IS_APPROX(s1*map1, map3);
  
  if(size<=256)
  {
    VERIFY_IS_EQUAL(map4, MatrixType::Ones(rows,cols));
    map4 = map1;
    MatrixType ma4 = map4;
    VERIFY_IS_EQUAL(map1, map4);
    VERIFY_IS_EQUAL(ma1, map4);
    VERIFY_IS_EQUAL(ma1, ma4);
    VERIFY_IS_APPROX(s1*map1, s1*map4);
    
    map4 *= s1;
    VERIFY_IS_APPROX(s1*map1, map4);
  }

  internal::aligned_delete(array1, size);
  internal::aligned_delete(array2, size);
  delete[] array3;
}
Beispiel #3
0
/***************************************************************************
 * @brief GSkymap_healpix_construct
 ***************************************************************************/
void TestGSky::test_GSkymap_healpix_construct(void)
{

    // Test void constructor
    test_try("Test void constructor");
    try {
        GSkymap map;
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Test correct Healpix constructors
    test_try("Test correct Healpix constructors");
    try {
        GSkymap ring1("GAL", 1, "RING", 1);
        GSkymap ring2("GAL", 2, "RING", 1);
        GSkymap ring4("GAL", 4, "RING", 1);
        GSkymap ring8("GAL", 8, "RING", 1);
        GSkymap ring16("GAL", 16, "RING", 1);
        GSkymap ring32("GAL", 32, "RING", 1);
        GSkymap ring64("GAL", 64, "RING", 1);
        GSkymap ring128("GAL", 128, "RING", 1);
        GSkymap ring256("GAL", 256, "RING", 1);
        GSkymap ring512("GAL", 512, "RING", 1);
        GSkymap nest1("GAL", 1, "NEST", 1);
        GSkymap nest2("GAL", 2, "NEST", 1);
        GSkymap nest4("GAL", 4, "NEST", 1);
        GSkymap nest8("GAL", 8, "NEST", 1);
        GSkymap nest16("GAL", 16, "NEST", 1);
        GSkymap nest32("GAL", 32, "NEST", 1);
        GSkymap nest64("GAL", 64, "NEST", 1);
        GSkymap nest128("GAL", 128, "NEST", 1);
        GSkymap nest256("GAL", 256, "NEST", 1);
        GSkymap nest512("GAL", 512, "NEST", 1);
        GSkymap map1("CEL", 1, "RING", 1);
        GSkymap map2("CEL", 1, "RING", 2);
        GSkymap map3("EQU", 1, "RING", 1);
        GSkymap map4("EQU", 1, "NESTED", 1);

        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Test Healpix copy constructor
    test_try("Test Healpix copy constructor");
    try {
        GSkymap ring1("GAL", 1, "RING", 1);
        GSkymap ring2 = ring1;

        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Test invalid coordsys in constructor
    test_try("Test invalid coordsys in constructor");
    try {
        GSkymap map("HOR", 1, "RING", 1);
        test_try_failure();
    }
    catch (GException::wcs_bad_coords &e) {
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Test invalid nside in constructor
    test_try("Test invalid nside in constructor");
    try {
        GSkymap map("GAL", 3, "RING", 1);
        test_try_failure();
    }
    catch (GException::wcs_hpx_bad_nside &e) {
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Test invalid ordering in constructor
    test_try("Test invalid ordering in constructor");
    try {
        GSkymap map("GAL", 2, "SPHERICAL", 1);
        test_try_failure();
    }
    catch (GException::wcs_hpx_bad_ordering &e) {
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }


    // Test invalid nmaps in constructor
    test_try("Test invalid nmaps in constructor");
    try {
        GSkymap map("GAL", 2, "NEST", 0);
        test_try_failure();
    }
    catch (GException::skymap_bad_par &e) {
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Exit test
    return;

}
Beispiel #4
0
MojErr MojHashMapTest::run()
{
    MojHashMap<int, int> map1, map2;
    MojHashMap<int, int>::Iterator i1, i2;
    MojHashMap<int, int>::ConstIterator ci1, ci2;
    MojHashMap<MojString, int> map3;
    MojHashMap<MojString, int> map4(map3);
    MojHashMap<const MojChar*, int> map5, map6;
    MojHashMap<MojString, int, const MojChar*> map7;
    MojString str1, str2;
    int val1, count;
    bool found;

    // empty tests
    MojTestAssert(map1.size() == 0);
    MojTestAssert(map1.empty());
    MojTestAssert(map1.begin() == map1.end());
    map1.clear();
    map1.swap(map1);
    map1.swap(map2);
    map1.assign(map1);
    map1.assign(map2);
    map1 = map1;
    map1 = map2;
    MojErr err = map1.begin(i1);
    MojTestErrCheck(err);
    err = map1.end(i2);
    MojTestErrCheck(err);
    MojTestAssert(i1 == i2);
    MojTestAssert(!map1.contains(5));
    MojTestAssert(!map1.get(1, val1));
    err = map1.del(1, found);
    MojTestErrCheck(err);
    MojTestAssert(!found);
    MojTestAssert(map1.find(1) == map1.end());
    err = map1.find(1, i1);
    MojTestErrCheck(err);
    MojTestAssert(i1 == map1.end());

    // put/get/find/del
    for (int i = 0; i < 100; ++i) {
        MojTestAssert(!map1.contains(i));
        err = map1.put(i, i);
        MojTestErrCheck(err);
        MojTestAssert(map1.contains(i));
        MojTestAssert(map1.get(i, val1));
        MojTestAssert(val1 == i);
        ci1 = map1.find(i);
        MojTestAssert(ci1 != map1.end());
        MojTestAssert(ci1.key() == i);
        MojTestAssert(ci1.value() == i);
        err = map1.find(i, i1);
        MojTestErrCheck(err);
        MojTestAssert(i1 != map1.end());
        MojTestAssert(i1.key() == i);
        MojTestAssert(i1.value() == i);
        err = map1.put(i, -i);
        MojTestErrCheck(err);
        ci1 = map1.find(i);
        MojTestAssert(ci1 != map1.end());
        MojTestAssert(ci1.key() == i);
        MojTestAssert(ci1.value() == -i);
        err = map1.del(i, found);
        MojTestErrCheck(err);
        MojTestAssert(found);
        MojTestAssert(!map1.contains(i));
        err = map1.del(i, found);
        MojTestErrCheck(err);
        MojTestAssert(!found);
        err = map1.put(i, i * 2);
        MojTestErrCheck(err);
        err = map1.find(i, i1);
        MojTestErrCheck(err);
        err = map1.del(i1.key(), found);
        MojTestErrCheck(err);
        MojTestAssert(!map1.contains(i));
        err = map1.put(i, i);
        MojTestErrCheck(err);
        MojTestAssert(map1.size() == (MojSize) i + 1);
        err = check(map1, i + 1, count);
        MojTestErrCheck(err);
        MojTestAssert(count == i + 1);
    }

    // iterate from find
    ci1 = map1.find(28);
    MojTestAssert(ci1 != map1.end());
    while (ci1 != map1.end())
        ++ci1;

    // delete while iterating
    map1.swap(map2);
    err = map2.begin(i1);
    MojTestErrCheck(err);
    while (i1 != map2.end()) {
        err = map2.del(i1++.key(), found);
        MojTestErrCheck(err);
        --count;
    }

    // assign/refcounting
    MojTestAssert(count == 0);
    MojTestAssert(map1.empty());
    MojTestAssert(map2.empty());
    MojTestAssert(!map2.contains(4));
    err = map1.put(4, 3);
    MojTestErrCheck(err);
    map2.assign(map1);
    MojTestAssert(map1.size() == map2.size());
    ci1 = map1.find(4);
    ci2 = map2.find(4);
    MojTestAssert(ci1 != map1.end() && ci2 != map2.end());
    MojTestAssert(&ci1.value() == &ci2.value());
    err = map1.put(5, 6);
    MojTestErrCheck(err);
    MojTestAssert(map1.contains(5));
    MojTestAssert(!map2.contains(5));

    // strings
    err = str1.assign(_T("hello"));
    MojTestErrCheck(err);
    err = map3.put(str1, 8);
    MojTestErrCheck(err);
    MojTestAssert(map3.get(str1, val1));
    MojTestAssert(val1 == 8);
    err = map5.put(_T("howdy"), 27);
    MojTestAssert(map5.get(_T("howdy"), val1));
    MojTestAssert(val1 == 27);
    err = map7.put(str1, 89);
    MojTestErrCheck(err);
    MojTestAssert(map7.get(str1, val1));
    MojTestAssert(val1 == 89);
    MojTestAssert(map7.get(_T("hello"), val1));
    MojTestAssert(val1 == 89);

    return MojErrNone;
}