Added final tests for checking start time

This commit is contained in:
GPayne
2020-02-11 07:20:29 -07:00
parent 016baa7ce7
commit 9d34a8d39e
3 changed files with 62 additions and 21 deletions

View File

@@ -34,20 +34,11 @@
namespace openspace::globebrowsing {
/*TimeQuantizer::TimeQuantizer(const std::string& start, const std::string& end,
double resolution)
: _start(start)
, _resolution(resolution)
, _timerange(start, end)
{
//setStartEndRange(start, end);
}*/
TimeQuantizer::TimeQuantizer(const std::string& start, const std::string& end,
const std::string& resolution)
: _start(start)
, _timerange(start, end)
//TimeQuantizer(start, end, parseTimeResolutionStr(resolution))
{
verifyStartTimeRestrictions();
_resolution = parseTimeResolutionStr(resolution);

View File

@@ -328,18 +328,6 @@ private:
class TimeQuantizer {
public:
TimeQuantizer() = default;
/*
* Constructor that initializes with formatted strings for start & ends date/times,
* and a time resolution within that range
*
* \params start the ISO8601 date/time string (YYYY-MM-DDTHH:mm:ss) for start
* limitations on values include: day of month in range of 1 - 28,
* and hour, minute, second values must be 0.
* \params end the ISO8601 date/time string (YYYY-MM-DDTHH:mm:ss) for end
* \params resolution the number of seconds between the temporal data set updates
*/
//TimeQuantizer(const std::string& start, const std::string& end, double resolution);
/*
* Constructor that initializes with formatted strings for start & ends date/times,
* and a time resolution within that range

View File

@@ -99,6 +99,46 @@ static void singleResolutionTest(openspace::globebrowsing::TimeQuantizer& tq,
}
}
static void singleStartTimeTest1(openspace::globebrowsing::TimeQuantizer& tq,
std::string startTime, std::string expectedErrSubstring,
bool expectFailure)
{
std::string res;
try {
tq.setStartEndRange(startTime, startTime);
}
catch (const ghoul::RuntimeError& e) {
res = e.message;
}
if (expectFailure) {
EXPECT_TRUE(res.find(expectedErrSubstring) != std::string::npos);
}
else {
EXPECT_TRUE(res.find(expectedErrSubstring) == std::string::npos);
}
}
static void singleStartTimeTest2(std::string startTime, std::string expectedErrSubstring,
bool expectFailure)
{
using namespace openspace::globebrowsing;
std::string res;
try {
TimeQuantizer tq(startTime, startTime, "1d");
}
catch (const ghoul::RuntimeError& e) {
res = e.message;
}
if (expectFailure) {
EXPECT_TRUE(res.find(expectedErrSubstring) != std::string::npos);
}
else {
EXPECT_TRUE(res.find(expectedErrSubstring) == std::string::npos);
}
}
static void LoadSpiceKernel () {
loadLSKKernel();
// naif0008.tls is a text file, check if loaded.
@@ -279,3 +319,25 @@ TEST_F(TimeQuantizerTest, TestResolutionError) {
singleResolutionTest(t1, "31m", "(m)inute option.", true);
singleResolutionTest(t1, "10s", "unit format", true);
}
TEST_F(TimeQuantizerTest, TestStartTimeError1) {
LoadSpiceKernel();
using namespace openspace::globebrowsing;
TimeQuantizer t1;
singleStartTimeTest1(t1, "2017-01-20T00:00:00", "Invalid start", false);
singleStartTimeTest1(t1, "2017-01-29T00:00:00", "Invalid start day value", true);
singleStartTimeTest1(t1, "2017-01-28T12:00:00", "Invalid start time value", true);
singleStartTimeTest1(t1, "2017-01-28T00:01:00", "Invalid start time value", true);
singleStartTimeTest1(t1, "2017-01-28T00:00:01", "Invalid start time value", true);
}
TEST_F(TimeQuantizerTest, TestStartTimeError2) {
LoadSpiceKernel();
singleStartTimeTest2("2017-01-20T00:00:00", "Invalid start", false);
singleStartTimeTest2("2017-01-29T00:00:00", "Invalid start day value", true);
singleStartTimeTest2("2017-01-28T12:00:00", "Invalid start time value", true);
singleStartTimeTest2("2017-01-28T00:01:00", "Invalid start time value", true);
singleStartTimeTest2("2017-01-28T00:00:01", "Invalid start time value", true);
}