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
#ifndef MANTID_KERNEL_MAKEUNIQUETEST_H_
#define MANTID_KERNEL_MAKEUNIQUETEST_H_
#include "MantidKernel/make_unique.h"
#include <cxxtest/TestSuite.h>
using namespace Mantid;
using namespace Mantid::Kernel;
struct Vec3 {
int x, y, z;
Vec3() : x(0), y(0), z(0) {}
Vec3(int x, int y, int z) : x(x), y(y), z(z) {}
};
class MakeUniqueTest : public CxxTest::TestSuite {
public:
void test_default_constructor() {
// Use the default constructor.
std::unique_ptr<Vec3> v1 = make_unique<Vec3>();
TS_ASSERT_EQUALS(v1->x, 0);
TS_ASSERT_EQUALS(v1->y, 0);
TS_ASSERT_EQUALS(v1->z, 0);
}
void test_another_constructor() {
// Use the constructor that matches these arguments
std::unique_ptr<Vec3> v2 = make_unique<Vec3>(0, 1, 2);
TS_ASSERT_EQUALS(v2->x, 0);
TS_ASSERT_EQUALS(v2->y, 1);
TS_ASSERT_EQUALS(v2->z, 2);
}
void test_array_five_elements() {
// Create a unique_ptr to an array of 5 elements
std::unique_ptr<Vec3[]> v3 = make_unique<Vec3[]>(5);
for (int i = 0; i < 5; i++) {
TS_ASSERT_EQUALS(v3[i].x, 0);
TS_ASSERT_EQUALS(v3[i].y, 0);
TS_ASSERT_EQUALS(v3[i].z, 0);
}
}
};
#endif /* MANTID_KERNEL_MAKEUNIQUETEST_H_ */