Skip to content

Commit

Permalink
bit: Fix missing namespace of size_t in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
stotko committed Feb 18, 2020
1 parent 388971c commit cc3dafc
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions test/stdgpu/bit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ popcount<unsigned long long int>(const unsigned long long int);

void
thread_ispow2_random(const stdgpu::index_t iterations,
const std::unordered_set<size_t>& pow2_list)
const std::unordered_set<std::size_t>& pow2_list)
{
// Generate true random numbers
size_t seed = test_utils::random_thread_seed();
std::size_t seed = test_utils::random_thread_seed();

std::default_random_engine rng(seed);
std::uniform_int_distribution<size_t> dist(std::numeric_limits<size_t>::lowest(), std::numeric_limits<size_t>::max());
std::uniform_int_distribution<std::size_t> dist(std::numeric_limits<std::size_t>::lowest(), std::numeric_limits<std::size_t>::max());

for (stdgpu::index_t i = 0; i < iterations; ++i)
{
size_t number = dist(rng);
std::size_t number = dist(rng);

if (pow2_list.find(number) == pow2_list.end())
{
Expand All @@ -110,10 +110,10 @@ thread_ispow2_random(const stdgpu::index_t iterations,

TEST_F(stdgpu_bit, ispow2)
{
std::unordered_set<size_t> pow2_list;
for (size_t i = 0; i < std::numeric_limits<size_t>::digits; ++i)
std::unordered_set<std::size_t> pow2_list;
for (std::size_t i = 0; i < std::numeric_limits<std::size_t>::digits; ++i)
{
size_t pow2_i = static_cast<size_t>(1) << i;
std::size_t pow2_i = static_cast<std::size_t>(1) << i;

ASSERT_TRUE(stdgpu::ispow2(pow2_i));

Expand All @@ -133,19 +133,19 @@ void
thread_ceil2_random(const stdgpu::index_t iterations)
{
// Generate true random numbers
size_t seed = test_utils::random_thread_seed();
std::size_t seed = test_utils::random_thread_seed();

std::default_random_engine rng(seed);
std::uniform_int_distribution<size_t> dist(std::numeric_limits<size_t>::lowest(), std::numeric_limits<size_t>::max());
std::uniform_int_distribution<std::size_t> dist(std::numeric_limits<std::size_t>::lowest(), std::numeric_limits<std::size_t>::max());

for (stdgpu::index_t i = 0; i < iterations; ++i)
{
size_t number = dist(rng);
std::size_t number = dist(rng);

// result will not be representable, so skip this sample
if (number > static_cast<size_t>(1) << (std::numeric_limits<size_t>::digits - 1)) continue;
if (number > static_cast<std::size_t>(1) << (std::numeric_limits<std::size_t>::digits - 1)) continue;

size_t result = stdgpu::ceil2(number);
std::size_t result = stdgpu::ceil2(number);

EXPECT_TRUE(stdgpu::ispow2(result));
EXPECT_GE(result, number);
Expand All @@ -165,24 +165,24 @@ TEST_F(stdgpu_bit, ceil2_random)

TEST_F(stdgpu_bit, ceil2_zero)
{
EXPECT_EQ(stdgpu::ceil2(static_cast<size_t>(0)), static_cast<size_t>(1));
EXPECT_EQ(stdgpu::ceil2(static_cast<std::size_t>(0)), static_cast<std::size_t>(1));
}


void
thread_floor2_random(const stdgpu::index_t iterations)
{
// Generate true random numbers
size_t seed = test_utils::random_thread_seed();
std::size_t seed = test_utils::random_thread_seed();

std::default_random_engine rng(seed);
std::uniform_int_distribution<size_t> dist(std::numeric_limits<size_t>::lowest(), std::numeric_limits<size_t>::max());
std::uniform_int_distribution<std::size_t> dist(std::numeric_limits<std::size_t>::lowest(), std::numeric_limits<std::size_t>::max());

for (stdgpu::index_t i = 0; i < iterations; ++i)
{
size_t number = dist(rng);
std::size_t number = dist(rng);

size_t result = stdgpu::floor2(number);
std::size_t result = stdgpu::floor2(number);

EXPECT_TRUE(stdgpu::ispow2(result));
EXPECT_LE(result, number);
Expand All @@ -202,31 +202,31 @@ TEST_F(stdgpu_bit, floor2_random)

TEST_F(stdgpu_bit, floor2_zero)
{
EXPECT_EQ(stdgpu::floor2(static_cast<size_t>(0)), static_cast<size_t>(0));
EXPECT_EQ(stdgpu::floor2(static_cast<std::size_t>(0)), static_cast<std::size_t>(0));
}


void
thread_mod2_random(const stdgpu::index_t iterations,
const size_t divider)
const std::size_t divider)
{
// Generate true random numbers
size_t seed = test_utils::random_thread_seed();
std::size_t seed = test_utils::random_thread_seed();

std::default_random_engine rng(seed);
std::uniform_int_distribution<size_t> dist(std::numeric_limits<size_t>::lowest(), std::numeric_limits<size_t>::max());
std::uniform_int_distribution<std::size_t> dist(std::numeric_limits<std::size_t>::lowest(), std::numeric_limits<std::size_t>::max());

for (stdgpu::index_t i = 0; i < iterations; ++i)
{
size_t number = dist(rng);
std::size_t number = dist(rng);
EXPECT_EQ(stdgpu::mod2(number, divider), number % divider);
}
}


TEST_F(stdgpu_bit, mod2_random)
{
const size_t divider = static_cast<size_t>(pow(2, 21));
const std::size_t divider = static_cast<std::size_t>(pow(2, 21));
stdgpu::index_t iterations_per_thread = static_cast<stdgpu::index_t>(pow(2, 19));

test_utils::for_each_concurrent_thread(&thread_mod2_random,
Expand All @@ -237,49 +237,49 @@ TEST_F(stdgpu_bit, mod2_random)

TEST_F(stdgpu_bit, mod2_one_positive)
{
size_t number = 42;
size_t divider = 1;
EXPECT_EQ(stdgpu::mod2(number, divider), static_cast<size_t>(0));
std::size_t number = 42;
std::size_t divider = 1;
EXPECT_EQ(stdgpu::mod2(number, divider), static_cast<std::size_t>(0));
}


TEST_F(stdgpu_bit, mod2_one_zero)
{
size_t number = 0;
size_t divider = 1;
EXPECT_EQ(stdgpu::mod2(number, divider), static_cast<size_t>(0));
std::size_t number = 0;
std::size_t divider = 1;
EXPECT_EQ(stdgpu::mod2(number, divider), static_cast<std::size_t>(0));
}


TEST_F(stdgpu_bit, log2pow2)
{
for (size_t i = 0; i < std::numeric_limits<size_t>::digits; ++i)
for (std::size_t i = 0; i < std::numeric_limits<std::size_t>::digits; ++i)
{
EXPECT_EQ(stdgpu::log2pow2(static_cast<size_t>(1) << i), static_cast<size_t>(i));
EXPECT_EQ(stdgpu::log2pow2(static_cast<std::size_t>(1) << i), static_cast<std::size_t>(i));
}
}


TEST_F(stdgpu_bit, popcount_zero)
{
EXPECT_EQ(stdgpu::popcount(static_cast<size_t>(0)), 0);
EXPECT_EQ(stdgpu::popcount(static_cast<std::size_t>(0)), 0);
}


TEST_F(stdgpu_bit, popcount_pow2)
{
for (size_t i = 0; i < std::numeric_limits<size_t>::digits; ++i)
for (std::size_t i = 0; i < std::numeric_limits<std::size_t>::digits; ++i)
{
EXPECT_EQ(stdgpu::popcount(static_cast<size_t>(1) << i), 1);
EXPECT_EQ(stdgpu::popcount(static_cast<std::size_t>(1) << i), 1);
}
}


TEST_F(stdgpu_bit, popcount_pow2m1)
{
for (size_t i = 0; i < std::numeric_limits<size_t>::digits; ++i)
for (std::size_t i = 0; i < std::numeric_limits<std::size_t>::digits; ++i)
{
EXPECT_EQ(stdgpu::popcount((static_cast<size_t>(1) << i) - 1), i);
EXPECT_EQ(stdgpu::popcount((static_cast<std::size_t>(1) << i) - 1), i);
}
}

0 comments on commit cc3dafc

Please sign in to comment.