I wrote method that return random number between two given numbers. Here it's header:
int NumRange(int low,int high);
I want to check that method really return all the range between those two numbers, so I wrote a test (here below), but in my opinion it's too complicated. Maybe there is another way to check it, or I'm the best:)
TEST_F(RandomGeneratorTest, fill_all_the_range)
{
// In set - there is no duplicates
std::set<int> results;
int i;
for (i=0;i<1000;i++)
results.insert(NumRange(0,9));
EXPECT_EQ(10, results.size());
}
Thank you, and sorry about my poor English.
EDIT: After question, I bring here below another test that I wrote to complete the test scenario.
TEST_F(RandomGeneratorTest, only_in_the_range)
{
int i,result;
for (i=0;i<1000;i++)
{
result = NumRange(0,9);
EXPECT_TRUE((result<=9) && (result>=0));
}
}
EDIT 2: Based on @cyborg answer (thank you), I made a histogram test (here below). But it's very complicated, and test, in my opinion, should be very simple, so my question still alive. I search simple way to check.
TEST_F(RandomGeneratorTest, fill_all_of_the_histogram_range)
{
int results[10]= {0};
int i, approxRes;
for (i=0;i<100000000;i++)
results[NumRange(0,9)]+=1;
for (i=0;i<10;i++)
{
approxRes = results[i]/10000;
EXPECT_TRUE((approxRes<=1001) && (approxRes>=999));
}
}