Skip to content

Commit

Permalink
add unit tests for some CMath::random functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Soeren Sonnenburg committed May 21, 2013
1 parent 9632374 commit 6acfcf4
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions tests/unit/mathematics/Random_unittest.cc
@@ -1,5 +1,6 @@
#include <shogun/lib/config.h>
#include <shogun/mathematics/Random.h>
#include <shogun/mathematics/Math.h>
#include <shogun/lib/SGVector.h>
#include <gtest/gtest.h>

Expand Down Expand Up @@ -106,3 +107,103 @@ TEST(Random, normal_distrib)

EXPECT_DOUBLE_EQ(t, r);
}

TEST(Random, random_uint64_1_2)
{
CMath::init_random(17);
for (int32_t i=0; i<10000; i++)
{
uint64_t r=CMath::random((uint64_t) 1, (uint64_t) 2);
EXPECT_TRUE(r == 1 || r == 2);
}
}

TEST(Random, random_uint64_0_10)
{
CMath::init_random(17);
int rnds[10] = {0,0,0,0,0,0};
for (int32_t i=0; i<10000; i++)
{
uint64_t r=CMath::random((uint64_t) 0, (uint64_t) 9);
rnds[r]++;
}

for (int32_t i=0; i<10; i++) {
EXPECT_TRUE(rnds[i]>0);
}
}

TEST(Random, random_int64_1_2)
{
CMath::init_random(17);
for (int32_t i=0; i<10000; i++)
{
int64_t r=CMath::random((int64_t) 1, (int64_t) 2);
EXPECT_TRUE(r == 1 || r == 2);
}
}

TEST(Random, random_int64_0_10)
{
CMath::init_random(17);
int rnds[10] = {0,0,0,0,0,0};
for (int32_t i=0; i<10000; i++)
{
int64_t r=CMath::random((int64_t) 0, (int64_t) 9);
rnds[r]++;
}

for (int32_t i=0; i<10; i++) {
EXPECT_TRUE(rnds[i]>0);
}
}

TEST(Random, random_uint32_1_2)
{
CMath::init_random(17);
for (int32_t i=0; i<10000; i++)
{
uint32_t r=CMath::random((uint32_t) 1, (uint32_t) 2);
EXPECT_TRUE(r == 1 || r == 2);
}
}

TEST(Random, random_uint32_0_10)
{
CMath::init_random(17);
int rnds[10] = {0,0,0,0,0,0};
for (int32_t i=0; i<10000; i++)
{
uint32_t r=CMath::random((uint32_t) 0, (uint32_t) 9);
rnds[r]++;
}

for (int32_t i=0; i<10; i++) {
EXPECT_TRUE(rnds[i]>0);
}
}

TEST(Random, random_int32_1_2)
{
CMath::init_random(17);
for (int32_t i=0; i<10000; i++)
{
int32_t r=CMath::random((int32_t) 1, (int32_t) 2);
EXPECT_TRUE(r == 1 || r == 2);
}
}

TEST(Random, random_int32_0_10)
{
CMath::init_random(17);
int rnds[10] = {0,0,0,0,0,0};
for (int32_t i=0; i<10000; i++)
{
int32_t r=CMath::random((int32_t) 0, (int32_t) 9);
rnds[r]++;
}

for (int32_t i=0; i<10; i++) {
EXPECT_TRUE(rnds[i]>0);
}
}

0 comments on commit 6acfcf4

Please sign in to comment.