utestBoolArray.cpp 1.82 KB
Newer Older
1
// See LICENCE file at project root
2 3
#include "FUTester.hpp"

BRAMAS Berenger's avatar
BRAMAS Berenger committed
4
#include "Containers/FBoolArray.hpp"
5 6 7 8 9 10 11 12 13 14


/**
* This file is a unit test for the FBoolArray class
*/


/** this class test the bool array container */
class TestArray : public FUTester<TestArray> {

BRAMAS Berenger's avatar
BRAMAS Berenger committed
15 16 17 18
    void TestGetSet(){
        FBoolArray array(500);
        for(int idx = 0 ; idx < 500 ; ++idx){
            uassert(!array.get(idx));
19 20
        }

BRAMAS Berenger's avatar
BRAMAS Berenger committed
21 22 23 24 25 26
        for(int idx = 0 ; idx < 500 ; ++idx){
            array.set(idx, true);
            uassert(array.get(idx));
            array.set(idx, false);
            uassert(!array.get(idx));
        }
27

BRAMAS Berenger's avatar
BRAMAS Berenger committed
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
        for(int idx = 0 ; idx < 500 ; ++idx){
            array.set(idx, true);
        }
        array.setToZeros();
        for(int idx = 0 ; idx < 500 ; ++idx){
            uassert(!array.get(idx));
        }
        array.setToOnes();
        for(int idx = 0 ; idx < 500 ; ++idx){
            uassert(array.get(idx));
        }
    }

    void TestGetSet2(){
        FBoolArray array(100);

        for(int idx = 0 ; idx < 100 ; ++idx){
            if(idx%3){
                array.set(idx, true);
                uassert(array.get(idx));
            }
            else{
                uassert(!array.get(idx));
            }
        }
    }
54

BRAMAS Berenger's avatar
BRAMAS Berenger committed
55 56 57
    void TestEqual(){
        FBoolArray array1(10);
        FBoolArray array2(10);
58 59


BRAMAS Berenger's avatar
BRAMAS Berenger committed
60
        uassert(array1 == array2);
61

BRAMAS Berenger's avatar
BRAMAS Berenger committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
        array1.set(1, true);
        uassert(array1 != array2);

        array2.set(1, true);
        uassert(array1 == array2);

        array1.set(5, true);
        array2 = array1;
        uassert(array1 == array2);
    }

    // set test
    void SetTests(){
        AddTest(&TestArray::TestGetSet,"Test Get & Set");
        AddTest(&TestArray::TestGetSet2,"Test Get & Set 2");
        AddTest(&TestArray::TestEqual,"Test Equal");
    }
79 80 81 82 83 84
};

// You must do this
TestClass(TestArray)