Newer
Older
#ifndef MANTID_API_FREEBLOCKTEST_H_
#define MANTID_API_FREEBLOCKTEST_H_
Janik Zikovsky
committed
#include "MantidKernel/FreeBlock.h"
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
#include "MantidKernel/System.h"
#include "MantidKernel/Timer.h"
#include <cxxtest/TestSuite.h>
#include <iomanip>
#include <iostream>
using namespace Mantid;
using namespace Mantid::Kernel;
class FreeBlockTest : public CxxTest::TestSuite
{
public:
void test_constructor()
{
FreeBlock b;
TS_ASSERT_EQUALS( b.getFilePosition(), 0 );
TS_ASSERT_EQUALS( b.getSize(), 0 );
FreeBlock b2(123,456);
TS_ASSERT_EQUALS( b2.getFilePosition(), 123 );
TS_ASSERT_EQUALS( b2.getSize(), 456 );
FreeBlock b3(b2);
TS_ASSERT_EQUALS( b3.getFilePosition(), 123 );
TS_ASSERT_EQUALS( b3.getSize(), 456 );
}
void test_assignment()
{
FreeBlock b2(123,456);
FreeBlock b3;
b3 = b2;
TS_ASSERT_EQUALS( b3.getFilePosition(), 123 );
TS_ASSERT_EQUALS( b3.getSize(), 456 );
}
void test_merge()
{
FreeBlock b1(100, 100);
FreeBlock b2(200, 500);
// Merge that succeeds
TS_ASSERT( FreeBlock::merge(b1, b2) );
TS_ASSERT_EQUALS( b1.getFilePosition(), 100 );
TS_ASSERT_EQUALS( b1.getSize(), 600 );
// Merge that fails
FreeBlock b3(100, 100);
FreeBlock b4(201, 100);
TS_ASSERT( !FreeBlock::merge(b3, b4) );
TS_ASSERT_EQUALS( b3.getFilePosition(), 100 );
TS_ASSERT_EQUALS( b3.getSize(), 100 );
}
};
class FreeBlockTestPerformance : public CxxTest::TestSuite
{
public:
std::vector<FreeBlock> blocks;
size_t num;
void setUp()
{
num = 1000000;
// Make a list where 1/3 of the blocks are adjacent
for (size_t i=0; i<num; i++)
blocks.push_back( FreeBlock(i*10, (i%3==0) ? 10 : 7) );
}
void test_merge()
{
// Merge by going backwards through the list.
for (size_t i=num-1; i>0; i--)
FreeBlock::merge(blocks[i-1], blocks[i]);
// The first block is merged into size 17
TS_ASSERT_EQUALS( blocks[0].getSize(), 17);
}
};
#endif /* MANTID_API_FREEBLOCKTEST_H_ */