LeanPeakTest.h 4.93 KB
Newer Older
Whitfield, Ross's avatar
Whitfield, Ross committed
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
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once

#include "MantidKernel/V3D.h"

#include <cxxtest/TestSuite.h>

#include "MantidDataObjects/LeanPeak.h"

using namespace Mantid::DataObjects;
using namespace Mantid::Geometry;
using namespace Mantid::Kernel;

class LeanPeakTest : public CxxTest::TestSuite {
public:
  // This pair of boilerplate methods prevent the suite being created statically
  // This means the constructor isn't called when running other tests
  static LeanPeakTest *createSuite() { return new LeanPeakTest(); }
  static void destroySuite(LeanPeakTest *suite) { delete suite; }

  void test_default_constructor() {
    LeanPeak p;
    TS_ASSERT_EQUALS(p.getH(), 0.0)
    TS_ASSERT_EQUALS(p.getK(), 0.0)
    TS_ASSERT_EQUALS(p.getL(), 0.0)
    TS_ASSERT_EQUALS(p.getInitialEnergy(), 0.0)
    TS_ASSERT_EQUALS(p.getFinalEnergy(), 0.0)
    TS_ASSERT_EQUALS(p.getQSampleFrame(), V3D(0, 0, 0))
    TS_ASSERT_EQUALS(p.getQLabFrame(), V3D())

36
    TS_ASSERT_EQUALS(p.getDetectorID(), -1)
Whitfield, Ross's avatar
Whitfield, Ross committed
37
38
39
40
41
42
43
    TS_ASSERT_THROWS(p.getDetector(), const std::runtime_error &)
    TS_ASSERT_THROWS(p.getInstrument(), const std::runtime_error &)
    TS_ASSERT_THROWS(p.findDetector(), const std::runtime_error &)
    TS_ASSERT_THROWS(p.getDetectorPosition(), const std::runtime_error &)
    TS_ASSERT_THROWS(p.getDetectorPositionNoCheck(), const std::runtime_error &)
    TS_ASSERT_THROWS(p.getDetPos(), const std::runtime_error &)
    TS_ASSERT_THROWS(p.getSamplePos(), const std::runtime_error &)
44
45
46
47
48
    TS_ASSERT(std::isnan(p.getTOF()))
    TS_ASSERT(std::isnan(p.getScattering()))
    TS_ASSERT(std::isnan(p.getAzimuthal()))
    TS_ASSERT(std::isnan(p.getL1()))
    TS_ASSERT(std::isnan(p.getL2()))
Whitfield, Ross's avatar
Whitfield, Ross committed
49
50
51
52
  }

  void test_Qsample_constructor() {
    LeanPeak p(V3D(1, 2, 3));
53
54
    TS_ASSERT_EQUALS(p.getQSampleFrame(), V3D(1, 2, 3))
    TS_ASSERT_EQUALS(p.getQLabFrame(), V3D(1, 2, 3))
Whitfield, Ross's avatar
Whitfield, Ross committed
55
56
57
58
59
60
61

    // This goniometer should just swap x and y of q
    Mantid::Kernel::Matrix<double> gon(3, 3);
    gon[0][1] = 1;
    gon[1][0] = 1;
    gon[2][2] = 1;
    p.setGoniometerMatrix(gon);
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
89
90
91
92
    TS_ASSERT_EQUALS(p.getQSampleFrame(), V3D(1, 2, 3))
    TS_ASSERT_EQUALS(p.getQLabFrame(), V3D(2, 1, 3))

    p.setWavelength(1.);
    TS_ASSERT_DELTA(p.getInitialEnergy(), 81.8042024359, 1e-5)
    TS_ASSERT_DELTA(p.getFinalEnergy(), 81.8042024359, 1e-5)
    TS_ASSERT_DELTA(p.getWavelength(), 1., 1e-9)
  }

  void test_Qsample_gon_constructor() {

    // This goniometer should just swap x and y of q
    Mantid::Kernel::Matrix<double> gon(3, 3);
    gon[0][1] = 1;
    gon[1][0] = 1;
    gon[2][2] = 1;

    LeanPeak p(V3D(1, 2, 3), gon);

    TS_ASSERT_EQUALS(p.getQSampleFrame(), V3D(1, 2, 3))
    TS_ASSERT_EQUALS(p.getQLabFrame(), V3D(2, 1, 3))
  }

  void test_Qsample_wavelength_constructor() {
    LeanPeak p(V3D(1, 2, 3), 1.);
    TS_ASSERT_EQUALS(p.getQSampleFrame(), V3D(1, 2, 3))
    TS_ASSERT_EQUALS(p.getQLabFrame(), V3D(1, 2, 3))

    TS_ASSERT_DELTA(p.getInitialEnergy(), 81.8042024359, 1e-5)
    TS_ASSERT_DELTA(p.getFinalEnergy(), 81.8042024359, 1e-5)
    TS_ASSERT_DELTA(p.getWavelength(), 1., 1e-9)
93
94
    TS_ASSERT_DELTA(p.getDSpacing(), 1.679251908362714, 1e-9)
    TS_ASSERT_DELTA(p.getScattering(), 0.6046731932, 1e-9)
95
96
97
98
99
100
101
102
103
104
105
  }

  void test_Qsample_gon_wavelength_constructor() {

    // This goniometer should just swap x and y of q
    Mantid::Kernel::Matrix<double> gon(3, 3);
    gon[0][1] = 1;
    gon[1][0] = 1;
    gon[2][2] = 1;

    LeanPeak p(V3D(1, 2, 3), gon, 1.);
Whitfield, Ross's avatar
Whitfield, Ross committed
106
107
108
109
110
111
112

    TS_ASSERT_EQUALS(p.getQSampleFrame(), V3D(1, 2, 3))
    TS_ASSERT_EQUALS(p.getQLabFrame(), V3D(2, 1, 3))
    TS_ASSERT_DELTA(p.getInitialEnergy(), 81.8042024359, 1e-5)
    TS_ASSERT_DELTA(p.getFinalEnergy(), 81.8042024359, 1e-5)
    TS_ASSERT_DELTA(p.getWavelength(), 1., 1e-9)
  }
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

  void test_copyConstructor() {
    // This goniometer should just swap x and y of q
    Mantid::Kernel::Matrix<double> gon(3, 3);
    gon[0][1] = 1;
    gon[1][0] = 1;
    gon[2][2] = 1;

    LeanPeak p(V3D(1, 2, 3), gon, 1.);
    // Default (not-explicit) copy constructor
    LeanPeak p2(p);
    TS_ASSERT_EQUALS(p.getQSampleFrame(), p2.getQSampleFrame());
    TS_ASSERT_EQUALS(p.getQLabFrame(), p2.getQLabFrame());
    TS_ASSERT_EQUALS(p.getGoniometerMatrix(), p2.getGoniometerMatrix());
  }
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

  void test_ConstructorFromIPeakInterface() {
    // This goniometer should just swap x and y of q
    Mantid::Kernel::Matrix<double> gon(3, 3);
    gon[0][1] = 1;
    gon[1][0] = 1;
    gon[2][2] = 1;

    LeanPeak p(V3D(1, 2, 3), gon, 1.);

    const Mantid::Geometry::IPeak &ipeak = p;
    LeanPeak p2(ipeak);
    TS_ASSERT_EQUALS(p.getQSampleFrame(), p2.getQSampleFrame());
    TS_ASSERT_EQUALS(p.getQLabFrame(), p2.getQLabFrame());
    TS_ASSERT_EQUALS(p.getGoniometerMatrix(), p2.getGoniometerMatrix());
  }
Whitfield, Ross's avatar
Whitfield, Ross committed
144
};