Skip to content

Commit

Permalink
Merge 04b24b2 into 046b6d9
Browse files Browse the repository at this point in the history
  • Loading branch information
offa committed Apr 26, 2019
2 parents 046b6d9 + 04b24b2 commit caa1fc3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
8 changes: 5 additions & 3 deletions include/CppUTest/Shuffle.h
Expand Up @@ -44,11 +44,13 @@ static inline int rand_(void) // rand_func_t
}

// "Durstenfeld shuffle" according to Wikipedia
static inline void shuffle_list(rand_func_t rand_func, int numElems, void* listToShuffleInPlace[])
static inline void shuffle_list(rand_func_t rand_func, size_t numElems, void* listToShuffleInPlace[])
{
for (int i = numElems - 1; i >= 1; --i)
if( numElems == 0 ) return;

for (size_t i = numElems - 1; i >= 1; --i)
{
int j = rand_func() % (i + 1); // distribution biased by modulo, but good enough for shuffling
const size_t j = ((size_t)rand_func()) % (i + 1); // distribution biased by modulo, but good enough for shuffling
void* e1 = listToShuffleInPlace[j];
void* e2 = listToShuffleInPlace[i];
listToShuffleInPlace[i] = e1;
Expand Down
3 changes: 2 additions & 1 deletion include/CppUTest/TestRegistry.h
Expand Up @@ -33,6 +33,7 @@
#ifndef D_TestRegistry_h
#define D_TestRegistry_h

#include "StandardCLibrary.h"
#include "SimpleString.h"
#include "TestFilter.h"
#include "Shuffle.h"
Expand All @@ -49,7 +50,7 @@ class TestRegistry

virtual void addTest(UtestShell *test);
virtual void unDoLastAddTest();
virtual int countTests();
virtual size_t countTests();
virtual void runAllTests(TestResult& result);
virtual void shuffleRunOrder(rand_func_t);
virtual void listTestGroupNames(TestResult& result);
Expand Down
2 changes: 1 addition & 1 deletion include/CppUTest/Utest.h
Expand Up @@ -93,7 +93,7 @@ class UtestShell

virtual UtestShell* addTest(UtestShell* test);
virtual UtestShell *getNext() const;
virtual int countTests();
virtual size_t countTests();

bool shouldRun(const TestFilter* groupFilters, const TestFilter* nameFilters) const;
const SimpleString getName() const;
Expand Down
8 changes: 4 additions & 4 deletions src/CppUTest/TestRegistry.cpp
Expand Up @@ -128,7 +128,7 @@ bool TestRegistry::endOfGroup(UtestShell* test)
return (!test || !test->getNext() || test->getGroup() != test->getNext()->getGroup());
}

int TestRegistry::countTests()
size_t TestRegistry::countTests()
{
return tests_ ? tests_->countTests() : 0;
}
Expand Down Expand Up @@ -234,11 +234,11 @@ void TestRegistry::shuffleRunOrder(rand_func_t rand_func)
{
return;
}
int numTests = getFirstTest()->countTests();
const size_t numTests = getFirstTest()->countTests();
typedef UtestShell* listElem;
listElem* tests = new listElem[numTests];
UtestShell *test = getFirstTest();
for (int testsIdx = 0; testsIdx < numTests; ++testsIdx)
for (size_t testsIdx = 0; testsIdx < numTests; ++testsIdx)
{
tests[testsIdx] = test;
test = test->getNext();
Expand All @@ -247,7 +247,7 @@ void TestRegistry::shuffleRunOrder(rand_func_t rand_func)

// Store shuffled list back to linked list
UtestShell *prev = NULLPTR;
for (int i = 0; i < numTests; ++i)
for (size_t i = 0; i < numTests; ++i)
{
prev = tests[numTests - 1 - i]->addTest(prev);
}
Expand Down
2 changes: 1 addition & 1 deletion src/CppUTest/Utest.cpp
Expand Up @@ -227,7 +227,7 @@ UtestShell* UtestShell::addTest(UtestShell *test)
return this;
}

int UtestShell::countTests()
size_t UtestShell::countTests()
{
return next_ ? next_->countTests() + 1 : 1;
}
Expand Down

0 comments on commit caa1fc3

Please sign in to comment.