Commit 9b7440df authored by Mathieu Tillet's avatar Mathieu Tillet
Browse files

Add more complete tests

parent 0621fab2
......@@ -194,6 +194,9 @@ public:
bool dist = rebindata->isDistribution();
TS_ASSERT(dist);
TS_ASSERT(checkBinWidthMonotonic(rebindata, false));
AnalysisDataService::Instance().remove("test_in1D");
AnalysisDataService::Instance().remove("test_out");
}
......@@ -514,6 +517,9 @@ public:
TS_ASSERT_DELTA(outX[3], 34, 1e-5);
TS_ASSERT_DELTA(outX[4], 36, 1e-5);
TS_ASSERT_DELTA(outX[5], 37, 1e-5);
TS_ASSERT(checkBinWidthMonotonic(out, true));
AnalysisDataService::Instance().remove("test_Rebin_revLog");
}
......@@ -539,6 +545,9 @@ public:
TS_ASSERT_DELTA(outX[1], 34, 1e-5);
TS_ASSERT_DELTA(outX[2], 40, 1e-5);
TS_ASSERT_DELTA(outX[3], 42, 1e-5);
TS_ASSERT(checkBinWidthMonotonic(out, true));
AnalysisDataService::Instance().remove("test_Rebin_revLog");
}
......@@ -566,6 +575,9 @@ public:
TS_ASSERT_DELTA(outX[2], 13, 1e-5);
TS_ASSERT_DELTA(outX[3], 15, 1e-5);
TS_ASSERT_DELTA(outX[4], 16, 1e-5);
TS_ASSERT(checkBinWidthMonotonic(out, true));
AnalysisDataService::Instance().remove("test_Rebin_revLog");
}
......@@ -594,6 +606,7 @@ public:
TS_ASSERT_DELTA(outX[4], 85, 1e-5);
TS_ASSERT_DELTA(outX[5], 95, 1e-5);
TS_ASSERT_DELTA(outX[6], 100, 1e-5);
AnalysisDataService::Instance().remove("test_Rebin_revLog");
}
......@@ -656,6 +669,8 @@ public:
TS_ASSERT_DELTA(outX[4], 36, 1e-5);
TS_ASSERT_DELTA(outX[5], 37, 1e-5);
TS_ASSERT(checkBinWidthMonotonic(out, true));
AnalysisDataService::Instance().remove("test_Rebin_revLog");
}
......@@ -686,6 +701,8 @@ public:
TS_ASSERT_DELTA(outX[5], 59, 1e-5);
TS_ASSERT_DELTA(outX[6], 60, 1e-5);
TS_ASSERT(checkBinWidthMonotonic(out, true));
AnalysisDataService::Instance().remove("test_Rebin_revLog");
}
......@@ -713,6 +730,8 @@ public:
TS_ASSERT_DELTA(outX[3], 3.28445705, 1e-5);
TS_ASSERT_DELTA(outX[27], 10, 1e-5);
TS_ASSERT(checkBinWidthMonotonic(out, true));
AnalysisDataService::Instance().remove("test_Rebin_revLog");
}
......@@ -740,6 +759,8 @@ public:
TS_ASSERT_DELTA(outX[3], 2.8333333, 1e-5);
TS_ASSERT_DELTA(outX[30], 5, 1e-5);
TS_ASSERT(checkBinWidthMonotonic(out, true, true));
AnalysisDataService::Instance().remove("test_Rebin_revLog");
}
......@@ -860,6 +881,24 @@ private:
auto &yValues = ws->y(0);
TS_ASSERT_DELTA(yValues.rawData(), yExpected, 0.001);
}
bool checkBinWidthMonotonic(MatrixWorkspace_sptr ws, bool reverse = false, bool ignoreLastBin = false) {
size_t binEdgesTotal = ws->blocksize();
if (ignoreLastBin)
binEdgesTotal--;
auto binEdges = ws->binEdges(0);
double lastBinSize = binEdges[1] - binEdges[0];
for (size_t i = 1; i < binEdgesTotal; ++i) {
double currentBinSize = binEdges[i + 1] - binEdges[i];
if (((lastBinSize < currentBinSize) && reverse) || ((lastBinSize > currentBinSize) && !reverse)) {
return false;
}
lastBinSize = currentBinSize;
}
return true;
}
};
class RebinTestPerformance : public CxxTest::TestSuite {
......
......@@ -116,6 +116,56 @@ public:
TS_ASSERT_EQUALS(axis, expectedAxis);
}
void test_createAxisFromRebinParams_reverseLog() {
std::vector<double> rbParams = {1, -1, 37};
std::vector<double> axis;
VectorHelper::createAxisFromRebinParams(rbParams, axis, true, false, 1, 37, true);
std::vector<double> expectedAxis = {1, 22, 30, 34, 36, 37};
TS_ASSERT_EQUALS(axis, expectedAxis);
}
void test_createAxisFromRebinParams_reverseLogFullBins() {
std::vector<double> rbParams = {1, -1, 37};
std::vector<double> axis;
VectorHelper::createAxisFromRebinParams(rbParams, axis, true, false, 1, 37, true);
std::vector<double> expectedAxis = {1, 22, 30, 34, 36, 37};
TS_ASSERT_EQUALS(axis, expectedAxis);
}
void test_createAxisFromRebinParams_reverseLogWithDiffStep() {
std::vector<double> rbParams = {1, -2, 42};
std::vector<double> axis;
VectorHelper::createAxisFromRebinParams(rbParams, axis, true, false, 1, 42, true);
std::vector<double> expectedAxis = {1, 34, 40, 42};
TS_ASSERT_EQUALS(axis, expectedAxis);
}
void test_createAxisFromRebinParams_inverseSquareRoot() {
std::vector<double> rbParams = {1, 1, 3.5};
std::vector<double> axis;
VectorHelper::createAxisFromRebinParams(rbParams, axis, true, false, 1, 3.5, true, 0.5);
std::vector<double> expectedAxis = {1, 2, 2.707106781, 3.28445705, 3.5};
TS_ASSERT_DELTA(axis, expectedAxis, 1e-5);
}
void test_createAxisFromRebinParams_harmonicSeries() {
std::vector<double> rbParams = {1, 1, 3};
std::vector<double> axis;
VectorHelper::createAxisFromRebinParams(rbParams, axis, true, false, 1, 3, true, 1);
std::vector<double> expectedAxis = {1, 2, 2.5, 2.833333, 3};
TS_ASSERT_DELTA(axis, expectedAxis, 1e-5);
}
void test_CreateAxisFromRebinParams_MultipleSteps() {
std::vector<double> rbParams = {0, 2, 5, 3, 10, 1, 12};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment