diff --git a/Framework/HistogramData/CMakeLists.txt b/Framework/HistogramData/CMakeLists.txt index a0d9d4b59bce765c95929156f490074bf132301f..bf171dec5a6e4633fc58110d56651fb8d07b6aab 100644 --- a/Framework/HistogramData/CMakeLists.txt +++ b/Framework/HistogramData/CMakeLists.txt @@ -46,6 +46,7 @@ set ( INC_FILES inc/MantidHistogramData/PointStandardDeviations.h inc/MantidHistogramData/PointVariances.h inc/MantidHistogramData/Points.h + inc/MantidHistogramData/QuadraticGenerator.h inc/MantidHistogramData/Rebin.h inc/MantidHistogramData/Scalable.h inc/MantidHistogramData/Slice.h @@ -85,6 +86,7 @@ set ( TEST_FILES PointStandardDeviationsTest.h PointVariancesTest.h PointsTest.h + QuadraticGeneratorTest.h RebinTest.h ScalableTest.h SliceTest.h @@ -122,7 +124,7 @@ endif () set_property ( TARGET HistogramData PROPERTY FOLDER "MantidFramework" ) target_include_directories ( HistogramData PUBLIC ${Boost_INCLUDE_DIRS}) -target_link_libraries ( HistogramData LINK_PRIVATE ${TCMALLOC_LIBRARIES_LINKTIME} +target_link_libraries ( HistogramData LINK_PRIVATE ${TCMALLOC_LIBRARIES_LINKTIME} ${GSL_LIBRARIES} ${MANTIDLIBS} ) # Add the unit tests directory diff --git a/Framework/HistogramData/inc/MantidHistogramData/QuadraticGenerator.h b/Framework/HistogramData/inc/MantidHistogramData/QuadraticGenerator.h new file mode 100644 index 0000000000000000000000000000000000000000..5db4a94dcac1c7d0914b161674c465445c97c227 --- /dev/null +++ b/Framework/HistogramData/inc/MantidHistogramData/QuadraticGenerator.h @@ -0,0 +1,52 @@ +#ifndef MANTID_HISTOGRAMDATA_QUADRATICGENERATOR_H_ +#define MANTID_HISTOGRAMDATA_QUADRATICGENERATOR_H_ + +#include "MantidHistogramData/DllConfig.h" + +namespace Mantid { +namespace HistogramData { + +/** QuadraticGenerator : Makes quadratics + + Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge + National Laboratory & European Spallation Source + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://github.com/mantidproject/mantid> + Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class QuadraticGenerator { +public: + QuadraticGenerator(double a0, double a1, double a2) + : a0(a0), a1(a1), a2(a2) {} + + double operator()() { + const double x = static_cast<double>(count++); + return a0 + a1 * x + a2 * x * x; + } + +private: + double a0; + double a1; + double a2; + size_t count{0}; +}; + +} // namespace HistogramData +} // namespace Mantid + +#endif /* MANTID_HISTOGRAMDATA_QUADRATICGENERATOR_H_ */ diff --git a/Framework/HistogramData/test/QuadraticGeneratorTest.h b/Framework/HistogramData/test/QuadraticGeneratorTest.h new file mode 100644 index 0000000000000000000000000000000000000000..f710d92f46c907f962b0130ec74b4b5ea90fd6f7 --- /dev/null +++ b/Framework/HistogramData/test/QuadraticGeneratorTest.h @@ -0,0 +1,40 @@ +#ifndef MANTID_HISTOGRAMDATA_QUADRATICGENERATORTEST_H_ +#define MANTID_HISTOGRAMDATA_QUADRATICGENERATORTEST_H_ + +#include <cxxtest/TestSuite.h> + +#include "MantidHistogramData/QuadraticGenerator.h" + +#include <algorithm> + +using Mantid::HistogramData::QuadraticGenerator; + +class QuadraticGeneratorTest : 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 QuadraticGeneratorTest *createSuite() { + return new QuadraticGeneratorTest(); + } + static void destroySuite(QuadraticGeneratorTest *suite) { delete suite; } + + void test_length0() { + std::vector<double> x(0); + std::generate_n(x.begin(), 0, QuadraticGenerator(0.1, 0.2, 0.3)); + TS_ASSERT_EQUALS(x, std::vector<double>(0)); + } + + void test_length1() { + std::vector<double> x(1); + std::generate_n(x.begin(), 1, QuadraticGenerator(0.1, 0.2, 0.3)); + TS_ASSERT_EQUALS(x, std::vector<double>{0.1}); + } + + void test_length2() { + std::vector<double> x(2); + std::generate_n(x.begin(), 2, QuadraticGenerator(3, 2, 1)); + TS_ASSERT_DELTA(x, std::vector<double>({3, 6}), 1e-14); + } +}; + +#endif /* MANTID_HISTOGRAMDATA_QUADRATICGENERATORTEST_H_ */