Skip to content

Commit

Permalink
Increases test coverage of FileNorcomQnh
Browse files Browse the repository at this point in the history
  • Loading branch information
tnipen committed Dec 1, 2015
1 parent 092be48 commit c720a0d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
4 changes: 0 additions & 4 deletions src/File/NorcomQnh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ FileNorcomQnh::FileNorcomQnh(std::string iFilename, const Options& iOptions) :
for(int i = 0; i < mNTime; i++)
times.push_back(i);

if(!iOptions.getValues("elevs", mElevs[0])) {
Util::error("Missing 'elevs' option for '" + iFilename + "'");
}

// Determine the times for this filetype.
if(!iOptions.getValue("startTime", mStartTime)) {
Util::error("Missing 'startTime' option for '" + iFilename + "'");
Expand Down
2 changes: 1 addition & 1 deletion src/File/NorcomQnh.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class FileNorcomQnh : public File {
FileNorcomQnh(std::string iFilename, const Options& iOptions);
~FileNorcomQnh();
static std::string description();
std::string name() const {return "point";};
std::string name() const {return "norcom";};
protected:
FieldPtr getFieldCore(Variable::Type iVariable, int iTime) const;
void writeCore(std::vector<Variable::Type> iVariables);
Expand Down
8 changes: 8 additions & 0 deletions src/Testing/CalibratorRegression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ namespace {
CalibratorRegression calibrator(Variable::T, Options());
EXPECT_DEATH(calibrator.calibrate(from, &par), ".*");
}
// Missing parameter file
TEST_F(TestCalibratorRegression, invalid2) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
FileArome from("testing/files/10x10.nc");
Util::setShowError(false);
CalibratorRegression calibrator(Variable::T, Options());
EXPECT_DEATH(calibrator.calibrate(from, NULL), ".*");
}
TEST_F(TestCalibratorRegression, training) {
// R code:
// data = data.frame(x=c(4,5,9),y=c(3.2,5,14))
Expand Down
5 changes: 5 additions & 0 deletions src/Testing/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ namespace {
File* f = File::getScheme("missingfilename", Options());
EXPECT_EQ(NULL, f);
}
TEST_F(FileTest, factoryNorcom) {
File* f = File::getScheme("file=testing/files/norcom.txt", Options("type=norcomQnh lats=60 lons=9 elevs=100 names=Test numTimes=100 startTime=0 endTime=3"));
ASSERT_TRUE(f);
EXPECT_EQ("norcom", f->name());
}
TEST_F(FileTest, deaccumulate) {
// Create accumulation field
FileArome from("testing/files/1x1.nc");
Expand Down
28 changes: 25 additions & 3 deletions src/Testing/FileNorcomQnh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,37 @@ namespace {
// FieldPtr field = to.getField(Variable::P, 0);
// EXPECT_FLOAT_EQ(1, (*field)(0,0,0));
}
TEST_F(FileNorcomQnhTest, description) {
FileNorcomQnh::description();
}
TEST_F(FileNorcomQnhTest, valid) {
// Longitudes outside 360, -360 should be allowed
FileNorcomQnh("testing/files/test.txt", Options("lats=1 lons=300 elevs=3 numTimes=2 startTime=0 endTime=1 names=test"));
FileNorcomQnh("testing/files/test.txt", Options("lats=1 lons=370 elevs=3 numTimes=2 startTime=0 endTime=1 names=test"));
FileNorcomQnh("testing/files/test.txt", Options("lats=1 lons=-370 elevs=3 numTimes=2 startTime=0 endTime=1 names=test"));
}
TEST_F(FileNorcomQnhTest, invalid) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
Util::setShowError(false);
// lats, lons, elevs not the same
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=1,2 lons=2 elevs=3 numTimes=2 startTime=0 endTime=1")), ".*");
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=2 lons=2,3,2 elevs=3 numTimes=2 startTime=0 endTime=1")), ".*");
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=2 lons=2 elevs=3,2 numTimes=2 startTime=0 endTime=1")), ".*");
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=1,2 lons=2 elevs=3 names=test numTimes=2 startTime=0 endTime=1")), ".*");
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=2 lons=2,3,2 elevs=3 names=test numTimes=2 startTime=0 endTime=1")), ".*");
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=2 lons=2 elevs=3,2 names=test numTimes=2 startTime=0 endTime=1")), ".*");
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=1 lons=2 elevs=3 names=q,w numTimes=2 startTime=0 endTime=1")), ".*");

// Missing attributes
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lons=2 elevs=3 numTimes=2 startTime=0 endTime=1")), ".*");
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=1 elevs=3 numTimes=2 startTime=0 endTime=1")), ".*");
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=1 lons=2 numTimes=2 startTime=0 endTime=1")), ".*");
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=1 lons=2 elevs=3 startTime=0 endTime=1")), ".*");
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=1 lons=2 elevs=3 numTimes=2 endTime=1")), ".*");
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=1 lons=2 elevs=3 numTimes=2 startTime=0")), ".*");
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("")), ".*");

// Invalid latitude
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=101 lons=2 elevs=3 numTimes=2 startTime=0 endTime=1")), ".*");
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=-91 lons=180 elevs=3 numTimes=2 startTime=0 endTime=1")), ".*");

// Start/end time not in ascending order
EXPECT_DEATH(FileNorcomQnh("testing/files/test.txt", Options("lats=1 lons=2 elevs=3 names=q numTimes=2 startTime=1 endTime=0")), ".*");
}
Expand Down

0 comments on commit c720a0d

Please sign in to comment.