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
#ifndef SOBOLSEQUENCETEST_H_
#define SOBOLSEQUENCETEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidKernel/SobolSequence.h"
#include <iostream>
#include <iomanip>
using Mantid::Kernel::SobolSequence;
class SobolSequenceTest : public CxxTest::TestSuite
{
public:
void test_That_Object_Construction_Does_Not_Throw()
{
TS_ASSERT_THROWS_NOTHING(SobolSequence(1));
}
void test_That_Next_For_Two_Generators_Returns_Same_Value()
{
SobolSequence gen_1(3), gen_2(3);
const std::vector<double> seq1 = gen_1.nextPoint();
const std::vector<double> seq2 = gen_2.nextPoint();
assertVectorValuesEqual(seq1,seq2);
}
void test_That_A_Given_Seed_Produces_Expected_Sequence()
{
SobolSequence randGen(5);
double expectedValues[3][5] = \
{
{0.5,0.5,0.5,0.5,0.5},
{0.75,0.25,0.75,0.25,0.75},
{0.25,0.75,0.25,0.75,0.25},
};
// Check 10 numbers
for( std::size_t i = 0; i < 3; ++i )
{
const std::vector<double> randPoint = randGen.nextPoint();
for( std::size_t j = 0; j < 5; ++j)
{
TS_ASSERT_DELTA(randPoint[j], expectedValues[i][j], 1e-12);
}
}
}
private:
void assertVectorValuesEqual(const std::vector<double> lhs, const std::vector<double> rhs)
{
TS_ASSERT_EQUALS(lhs.size(), rhs.size());
assertVectorValuesOp(lhs, rhs, true);
}
void assertVectorValuesDiffer(const std::vector<double> lhs, const std::vector<double> rhs)
{
return assertVectorValuesOp(lhs, rhs, false);
}
void assertVectorValuesOp(const std::vector<double> lhs, const std::vector<double> rhs, const bool same)
{
for(size_t i = 0; i < lhs.size(); ++i)
{
if(same)
{
TS_ASSERT_EQUALS(lhs[i], rhs[i]);
}
else
{
TS_ASSERT_DIFFERS(lhs[i], rhs[i]);
}
}
}
};
class SobolSequenceTestPerformance : public CxxTest::TestSuite
{
public:
void test_Large_Number_Of_Next_Point_Calls()
{
const unsigned int ndimensions(14);
SobolSequence generator(ndimensions);
const size_t ncalls = 10000000;
size_t sumSizes(0); // Make sure the optimizer actuall does the loop
for(size_t i = 0; i < ncalls; ++i)
{
const std::vector<double> & point = generator.nextPoint();
sumSizes += point.size();
}
TS_ASSERT(sumSizes > 0);
}
};
#endif