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
#ifndef MANTID_KERNEL_UTILSTEST_H_
#define MANTID_KERNEL_UTILSTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidKernel/Timer.h"
#include "MantidKernel/System.h"
#include <iostream>
#include <iomanip>
#include "MantidKernel/Utils.h"
using namespace Mantid::Kernel;
class UtilsTest : public CxxTest::TestSuite
{
public:
/** Make a nested loop with each counter resetting at 0 */
void test_nestedForLoopIncrement()
{
size_t * counters = Utils::nestedForLoopSetUp(3);
size_t * counters_max = Utils::nestedForLoopSetUp(3, 10);
// The data
size_t data[10][10][10];
memset(data, 0, sizeof(data));
bool allDone = false;
while (!allDone)
{
data[counters[0]][counters[1]][counters[2]] = counters[0] * 10000 + counters[1] * 100 + counters[2];
allDone = Utils::nestedForLoopIncrement(3, counters, counters_max);
}
for (size_t x=0; x<10; x++)
for (size_t y=0; y<10; y++)
for (size_t z=0; z<10; z++)
{
TS_ASSERT_EQUALS( data[x][y][z], x*10000+y*100+z);
}
delete counters;
delete counters_max;
}
/** Make a nested loop but use a non-zero starting index for each counter */
void test_nestedForLoopIncrement_nonZeroMinimum()
{
size_t * counters = Utils::nestedForLoopSetUp(3, 4);
size_t * counters_min = Utils::nestedForLoopSetUp(3, 4);
size_t * counters_max = Utils::nestedForLoopSetUp(3, 8);
// The data
size_t data[10][10][10];
memset(data, 0, sizeof(data));
bool allDone = false;
while (!allDone)
{
data[counters[0]][counters[1]][counters[2]] = counters[0] * 10000 + counters[1] * 100 + counters[2];
allDone = Utils::nestedForLoopIncrement(3, counters, counters_max, counters_min);
}
for (size_t x=0; x<10; x++)
for (size_t y=0; y<10; y++)
for (size_t z=0; z<10; z++)
{
if ((x<4 || y<4 || z<4) || (x>=8 || y>=8 || z>=8))
{ TS_ASSERT_EQUALS( data[x][y][z], 0); }
else
{ TS_ASSERT_EQUALS( data[x][y][z], x*10000+y*100+z);}
}
delete counters;
delete counters_min;
delete counters_max;
}
};
#endif /* MANTID_KERNEL_UTILSTEST_H_ */