1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <gtest/gtest.h>
#include <arrayfire.h>
#include <af/dim4.hpp>
#include <af/traits.hpp>
#include <string>
#include <vector>
#include <testHelpers.hpp>
using std::string;
using std::vector;
template<typename T>
class Sobel : public ::testing::Test
{
public:
virtual void SetUp() {}
};
template<typename T>
class Sobel_Integer : public ::testing::Test
{
public:
virtual void SetUp() {}
};
// create a list of types to be tested
typedef ::testing::Types<float, double> TestTypes;
typedef ::testing::Types<int, unsigned, char, unsigned char, short, ushort> TestTypesInt;
// register the type list
TYPED_TEST_CASE(Sobel, TestTypes);
TYPED_TEST_CASE(Sobel_Integer, TestTypesInt);
template<typename Ti, typename To>
void testSobelDerivatives(string pTestFile)
{
if (noDoubleTests<Ti>()) return;
vector<af::dim4> numDims;
vector<vector<Ti> > in;
vector<vector<To> > tests;
readTests<Ti,To,int>(pTestFile, numDims, in, tests);
af::dim4 dims = numDims[0];
af_array dxArray = 0;
af_array dyArray = 0;
af_array inArray = 0;
ASSERT_EQ(AF_SUCCESS, af_create_array(&inArray, &(in[0].front()),
dims.ndims(), dims.get(), (af_dtype)af::dtype_traits<Ti>::af_type));
ASSERT_EQ(AF_SUCCESS, af_sobel_operator(&dxArray, &dyArray, inArray, 3));
To *dxData = new To[dims.elements()];
To *dyData = new To[dims.elements()];
ASSERT_EQ(AF_SUCCESS, af_get_data_ptr((void*)dxData, dxArray));
ASSERT_EQ(AF_SUCCESS, af_get_data_ptr((void*)dyData, dyArray));
vector<To> currDXGoldBar = tests[0];
vector<To> currDYGoldBar = tests[1];
size_t nElems = currDXGoldBar.size();
for (size_t elIter=0; elIter<nElems; ++elIter) {
ASSERT_EQ(currDXGoldBar[elIter], dxData[elIter])<< "at: " << elIter<< std::endl;
}
nElems = currDYGoldBar.size();
for (size_t elIter=0; elIter<nElems; ++elIter) {
ASSERT_EQ(currDYGoldBar[elIter], dyData[elIter])<< "at: " << elIter<< std::endl;
}
// cleanup
delete[] dxData;
delete[] dyData;
ASSERT_EQ(AF_SUCCESS, af_release_array(inArray));
ASSERT_EQ(AF_SUCCESS, af_release_array(dxArray));
ASSERT_EQ(AF_SUCCESS, af_release_array(dyArray));
}
TYPED_TEST(Sobel, Rectangle)
{
testSobelDerivatives<TypeParam, TypeParam>(string(TEST_DIR"/sobel/rectangle.test"));
}
TYPED_TEST(Sobel_Integer, Rectangle)
{
testSobelDerivatives<TypeParam, int>(string(TEST_DIR"/sobel/rectangle.test"));
}
|