utestP2PExclusion.cpp 5.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126

// ===================================================================================
// 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".
// ===================================================================================
#include "FUTester.hpp"

#include "Core/FP2PExclusion.hpp"
#include "Utils/FMath.hpp"

#include <memory>

/**
* This file is a unit test for the FNeigborIndexes classes
*/


/** this class test the list container */
class TestExclusion : public FUTester<TestExclusion> {
    const int Size = 100;

    void Exclusion2(){
        const int Width = 2;
        std::unique_ptr<int[]> grid(new int[Size*Size*Size]);
        for(int idxShape = 0 ; idxShape < FP2PExclusion<Width>::SizeShape ; ++idxShape){
            memset(grid.get(), 0, sizeof(int)*Size*Size*Size);

            for(int idxX = 0 ; idxX < Size ; ++idxX){
                for(int idxY = 0 ; idxY < Size ; ++idxY){
                    for(int idxZ = 0 ; idxZ < Size ; ++idxZ){
                        if(FP2PExclusion<Width>::GetShapeIdx(idxX,idxY,idxZ) == idxShape){
                            for(int idxX_neig = FMath::Max(0,idxX-1) ; idxX_neig < FMath::Min(Size,idxX+1) ; ++idxX_neig){
                                for(int idxY_neig = FMath::Max(0,idxY-1) ; idxY_neig < FMath::Min(Size,idxY+1) ; ++idxY_neig){
                                    for(int idxZ_neig = FMath::Max(0,idxZ-1) ; idxZ_neig < FMath::Min(Size,idxZ+1) ; ++idxZ_neig){
                                        uassert(grid[(idxX_neig*Size + idxY_neig)*Size + idxZ_neig] == 0);
                                        grid[grid[(idxX_neig*Size + idxY_neig)*Size + idxZ_neig]] = 1;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    void Exclusion1(){
        const int Width = 1;
        std::unique_ptr<int[]> grid(new int[Size*Size*Size]);
        for(int idxShape = 0 ; idxShape < FP2PExclusion<Width>::SizeShape ; ++idxShape){
            memset(grid.get(), 0, sizeof(int)*Size*Size*Size);

            for(int idxX = 0 ; idxX < Size ; ++idxX){
                for(int idxY = 0 ; idxY < Size ; ++idxY){
                    for(int idxZ = 0 ; idxZ < Size ; ++idxZ){
                        if(FP2PExclusion<Width>::GetShapeIdx(idxX,idxY,idxZ) == idxShape){
                            for(int idxX_neig = FMath::Max(0,idxX-1) ; idxX_neig < idxX ; ++idxX_neig){
                                for(int idxY_neig = FMath::Max(0,idxY-1) ; idxY_neig < idxY ; ++idxY_neig){
                                    for(int idxZ_neig = FMath::Max(0,idxZ-1) ; idxZ_neig < idxZ ; ++idxZ_neig){
                                        uassert(grid[(idxX_neig*Size + idxY_neig)*Size + idxZ_neig] == 0);
                                        grid[grid[(idxX_neig*Size + idxY_neig)*Size + idxZ_neig]] = 1;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    void Middle(){
        std::unique_ptr<int[]> grid(new int[Size*Size*Size]);
        for(int idxShape = 0 ; idxShape < FP2PMiddleExclusion::SizeShape ; ++idxShape){
            memset(grid.get(), 0, sizeof(int)*Size*Size*Size);

            for(int idxX = 0 ; idxX < Size ; ++idxX){
                for(int idxY = 0 ; idxY < Size ; ++idxY){
                    for(int idxZ = 0 ; idxZ < Size ; ++idxZ){
                        if(FP2PMiddleExclusion::GetShapeIdx(idxX,idxY,idxZ) == idxShape){
                            for(int idxX_neig = FMath::Max(0,idxX-1) ; idxX_neig < FMath::Min(Size,idxX+1) ; ++idxX_neig){
                                for(int idxY_neig = FMath::Max(0,idxY-1) ; idxY_neig < FMath::Min(Size,idxY+1) ; ++idxY_neig){
                                    for(int idxZ_neig = FMath::Max(0,idxZ-1) ; idxZ_neig < FMath::Min(Size,idxZ+1) ; ++idxZ_neig){
                                        const int diffx = idxX_neig-idxX;
                                        const int diffy = idxY_neig-idxY;
                                        const int diffz = idxZ_neig-idxZ;
                                        const int idx = (diffx+1)*9 + (diffy+1)*3 + (diffz+1);
                                        if(idx < 14){
                                            uassert(grid[(idxX_neig*Size + idxY_neig)*Size + idxZ_neig] == 0);
                                            grid[grid[(idxX_neig*Size + idxY_neig)*Size + idxZ_neig]] = 1;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }


    // set test
    void SetTests(){
        AddTest(&TestExclusion::Exclusion2,"Test 2 exclustion");
        AddTest(&TestExclusion::Exclusion1,"Test 1 exclustion");
        AddTest(&TestExclusion::Middle,"Test middle exclustion");
    }
};

// You must do this
TestClass(TestExclusion)