Commit 0dfdbfdf authored by BRAMAS Berenger's avatar BRAMAS Berenger

Debug quicksort mpi and add a unit test

parent 398c5f08
This diff is collapsed.
This diff is collapsed.
...@@ -76,31 +76,6 @@ protected: ...@@ -76,31 +76,6 @@ protected:
return left; return left;
} }
/* A local iteration of qs */
static void QsLocal(SortType array[], const CompareType& pivot,
IndexType myLeft, IndexType myRight,
IndexType& prefix, IndexType& sufix){
IndexType leftIter = myLeft;
IndexType rightIter = myRight;
while(true){
while(CompareType(array[leftIter]) <= pivot && leftIter < rightIter){
++leftIter;
}
while(leftIter <= rightIter && pivot < CompareType(array[rightIter])){
--rightIter;
}
if(rightIter < leftIter) break;
Swap(array[leftIter],array[rightIter]);
++leftIter;
--rightIter;
}
prefix = leftIter - myLeft;
sufix = myRight - myLeft - prefix + 1;
}
/* The sequential qs */ /* The sequential qs */
static void QsSequentialStep(SortType array[], const IndexType left, const IndexType right){ static void QsSequentialStep(SortType array[], const IndexType left, const IndexType right){
......
This diff is collapsed.
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#ifndef UTESTER_HPP #ifndef UTESTER_HPP
#define UTESTER_HPP #define UTESTER_HPP
#include "ScalFmmConfig.h"
#include <iostream> #include <iostream>
#include <list> #include <list>
...@@ -24,10 +25,10 @@ ...@@ -24,10 +25,10 @@
#define TestClass(X)\ #define TestClass(X)\
int main(void){\ int main(void){\
X Controller;\ X Controller;\
return Controller.Run();\ return Controller.Run();\
}\ }\
/** /**
...@@ -44,164 +45,164 @@ int main(void){\ ...@@ -44,164 +45,164 @@ int main(void){\
*/ */
template <class TestClass> template <class TestClass>
class FUTester{ class FUTester{
// Test function pointer // Test function pointer
typedef void (TestClass::*TestFunc)(void); typedef void (TestClass::*TestFunc)(void);
/** Test descriptor */ /** Test descriptor */
struct TestFuncDescriptor{ struct TestFuncDescriptor{
TestFunc func; //< Test adress TestFunc func; //< Test adress
std::string name; //< Test name std::string name; //< Test name
}; };
std::list<TestFuncDescriptor> tests; //< all tests std::list<TestFuncDescriptor> tests; //< all tests
int totalTests; //< number of tests int totalTests; //< number of tests
int currentTest; //< current processing test in the run int currentTest; //< current processing test in the run
int currentStep; //< current processing step in the run int currentStep; //< current processing step in the run
int failedSteps; //< number of failed step in the current test int failedSteps; //< number of failed step in the current test
int failedTests; //< number of failed tests int failedTests; //< number of failed tests
protected: protected:
/** Constructor */ /** Constructor */
FUTester(){ FUTester(){
totalTests = 0; totalTests = 0;
} }
/** Callback before processing test */ /** Callback before processing test */
virtual void Before(){} virtual void Before(){}
/** Callback after processing test */ /** Callback after processing test */
virtual void After(){} virtual void After(){}
/** Callback before each unit test */ /** Callback before each unit test */
virtual void PreTest(){} virtual void PreTest(){}
/** Callback after each unit test */ /** Callback after each unit test */
virtual void PostTest(){} virtual void PostTest(){}
/** /**
* This function has to add tests * This function has to add tests
* <code> AddTest(&MyTest::TestOne); </code> * <code> AddTest(&MyTest::TestOne); </code>
*/ */
virtual void SetTests() = 0; virtual void SetTests() = 0;
/** /**
* Add a test without giving a name * Add a test without giving a name
* @param inFunc test function address * @param inFunc test function address
*/ */
void AddTest(TestFunc inFunc){ void AddTest(TestFunc inFunc){
char buff[256]; char buff[256];
sprintf(buff,"Unnamed Test number %d",totalTests+1); sprintf(buff,"Unnamed Test number %d",totalTests+1);
AddTest(inFunc,buff); AddTest(inFunc,buff);
} }
/** /**
* Add a test with a name * Add a test with a name
* @param inFunc test function address * @param inFunc test function address
* @param inFuncName function name * @param inFuncName function name
*/ */
void AddTest(TestFunc inFunc, const std::string& inFuncName){ void AddTest(TestFunc inFunc, const std::string& inFuncName){
++totalTests; ++totalTests;
TestFuncDescriptor desc; TestFuncDescriptor desc;
desc.func = inFunc; desc.func = inFunc;
desc.name = inFuncName; desc.name = inFuncName;
tests.push_back(desc); tests.push_back(desc);
} }
/** /**
* To print a message manually in the test * To print a message manually in the test
* @param value a object that ostream can work on * @param value a object that ostream can work on
*/ */
template <class Output> template <class Output>
void Print(const Output& value){ void Print(const Output& value){
std::cout<< "--- Output from program : " << value << "\n"; std::cout<< "--- Output from program : " << value << "\n";
} }
/** /**
* To test * To test
* @param result the test result * @param result the test result
* if result is false test failed * if result is false test failed
*/ */
void uassert(const bool result){ void uassert(const bool result){
++currentStep; ++currentStep;
if(!result){ if(!result){
std::cout << ">> Step " << currentStep << " Failed\n"; std::cout << ">> Step " << currentStep << " Failed\n";
++failedSteps; ++failedSteps;
} }
} }
/** /**
* To test equality * To test equality
* @param v1 value one * @param v1 value one
* @param v2 value 2 * @param v2 value 2
* if v1 is not equal v2 test failed * if v1 is not equal v2 test failed
*/ */
template <class T> template <class T>
void equal(const T& v1, const T& v2){ void equal(const T& v1, const T& v2){
uassert(v1 == v2); uassert(v1 == v2);
} }
/** /**
* To test equality * To test equality
* @param v1 value one * @param v1 value one
* @param v2 value 2 * @param v2 value 2
* if v1 is equal v2 test failed * if v1 is equal v2 test failed
*/ */
template <class T> template <class T>
void different(const T& v1, const T& v2){ void different(const T& v1, const T& v2){
uassert(v1 != v2); uassert(v1 != v2);
} }
public : public :
/** /**
* Processing the test * Processing the test
* return application exit code (= nb of errors) * return application exit code (= nb of errors)
*/ */
int Run(){ int Run(){
tests.clear(); tests.clear();
// register tests // register tests
SetTests(); SetTests();
TestClass* const toTest = static_cast<TestClass*>(this); TestClass* const toTest = static_cast<TestClass*>(this);
currentTest = 0; currentTest = 0;
failedTests = 0; failedTests = 0;
Before(); Before();
// for each tests // for each tests
const typename std::list<TestFuncDescriptor>::const_iterator end = tests.end(); const typename std::list<TestFuncDescriptor>::const_iterator end = tests.end();
for(typename std::list<TestFuncDescriptor>::iterator iter = tests.begin() ; iter != end ; ++iter){ for(typename std::list<TestFuncDescriptor>::iterator iter = tests.begin() ; iter != end ; ++iter){
currentStep = 0; currentStep = 0;
failedSteps = 0; failedSteps = 0;
std::cout << "[Start] " << (*iter).name << "\n"; std::cout << "[Start] " << (*iter).name << "\n";
PreTest(); PreTest();
TestFunc ff = (*iter).func; TestFunc ff = (*iter).func;
(toTest->*ff)(); (toTest->*ff)();
PostTest(); PostTest();
if(failedSteps){ if(failedSteps){
std::cout << "[Finished] FAILED (" << failedSteps << "/" << currentStep<< " steps failed)\n"; std::cout << "[Finished] FAILED (" << failedSteps << "/" << currentStep<< " steps failed)\n";
++failedTests; ++failedTests;
} }
else{ else{
std::cout << "[Finished] PASSED (" << currentStep << " steps)\n"; std::cout << "[Finished] PASSED (" << currentStep << " steps)\n";
} }
++currentTest; ++currentTest;
} }
After(); After();
std::cout <<"Test is over, " << (totalTests-failedTests) << " Passed, " << failedTests << " Failed\n"; std::cout <<"Test is over, " << (totalTests-failedTests) << " Passed, " << failedTests << " Failed\n";
return failedTests; return failedTests;
} }
}; };
...@@ -210,33 +211,33 @@ public : ...@@ -210,33 +211,33 @@ public :
#include "../Src/Utils/FMpi.hpp" #include "../Src/Utils/FMpi.hpp"
#define TestClassMpi(X) \ #define TestClassMpi(X) \
int main(int argc, char** argv){ \ int main(int argc, char** argv){ \
X Controller(argc,argv); \ X Controller(argc,argv); \
return Controller.Run(); \ return Controller.Run(); \
} \ } \
template <class TestClass> template <class TestClass>
class FUTesterMpi : public FUTester<TestClass>{ class FUTesterMpi : public FUTester<TestClass>{
protected: protected:
FMpi app; FMpi app;
//Constructor with params to initialize FMpi //Constructor with params to initialize FMpi
FUTesterMpi(int argc, char ** argv) : app(argc,argv){ FUTesterMpi(int argc, char ** argv) : app(argc,argv){
} }
/** /**
* To print a message manually in the test * To print a message manually in the test
* @param value a object that ostream can work on * @param value a object that ostream can work on
*/ */
template <class Output> template <class Output>
void Print(const Output& value){ void Print(const Output& value){
if(app.global().processId()==0){ if(app.global().processId()==0){
std::cout<< "--- Output from program : " << value << "\n"; std::cout<< "--- Output from program : " << value << "\n";
}
} }
}
}; };
#endif #endif
#endif #endif
// ===================================================================================
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Bérenger Bramas, Matthias Messner
// olivier.coulaud@inria.fr, berenger.bramas@inria.fr
// This software is a computer program whose purpose is to compute the FMM.
//
// This software is governed by the CeCILL-C and LGPL licenses and
// abiding by the rules of distribution of free software.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info".
// "http://www.gnu.org/licenses".
// ===================================================================================
#ifndef UTESTMPIQS_HPP #ifndef UTESTMPIQS_HPP
#define UTESTMPIQS_HPP #define UTESTMPIQS_HPP
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment