Skip to content

Commit

Permalink
Add variable unit tests to SnodasDataReaderTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Van committed May 16, 2022
1 parent d314f58 commit 83b1004
Showing 1 changed file with 130 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,134 @@ void swe() {

griddedData.done();
}

@Test
void snowDepth() {
if(outFile == null) Assertions.fail();
GriddedData griddedData = new GriddedData();
griddedData.setDSSFileName(outFile.getAbsolutePath());
griddedData.setPathname("///SNOW DEPTH/31OCT2019:0600///");

GridData gridData = new GridData();
int[] status = new int[1];
griddedData.retrieveGriddedData(true, gridData, status);
if (status[0] < 0) {
Assertions.fail();
}

GridInfo gridInfo = gridData.getGridInfo();
Assertions.assertEquals("MM", gridInfo.getDataUnits());
Assertions.assertEquals(DssDataType.INST_VAL.value(), gridInfo.getDataType());
Assertions.assertEquals("31 October 2019, 06:00", gridInfo.getStartTime());
Assertions.assertEquals("31 October 2019, 06:00", gridInfo.getEndTime());
Assertions.assertEquals(-4257.028, gridInfo.getMeanValue(), 1E-3);
Assertions.assertEquals(32767.0, gridInfo.getMaxValue(), 1E-3);
Assertions.assertEquals(-9999.0, gridInfo.getMinValue(), 1E-3);

griddedData.done();
}

@Test
void snowMeltRunoff() {
if(outFile == null) Assertions.fail();
GriddedData griddedData = new GriddedData();
griddedData.setDSSFileName(outFile.getAbsolutePath());
griddedData.setPathname("///LIQUID WATER/31OCT2019:0600/01NOV2019:0600//");

GridData gridData = new GridData();
int[] status = new int[1];
griddedData.retrieveGriddedData(true, gridData, status);
if (status[0] < 0) {
Assertions.fail();
}

GridInfo gridInfo = gridData.getGridInfo();
Assertions.assertEquals("M", gridInfo.getDataUnits());
Assertions.assertEquals(DssDataType.PER_CUM.value(), gridInfo.getDataType());
Assertions.assertEquals("31 October 2019, 06:00", gridInfo.getStartTime());
Assertions.assertEquals("1 November 2019, 06:00", gridInfo.getEndTime());
Assertions.assertEquals(-0.090, gridInfo.getMeanValue(), 1E-3);
Assertions.assertEquals(0.024, gridInfo.getMaxValue(), 1E-3);
Assertions.assertEquals(-0.100, gridInfo.getMinValue(), 1E-3);

griddedData.done();
}

@Test
void snowSublimation() {
if(outFile == null) Assertions.fail();
GriddedData griddedData = new GriddedData();
griddedData.setDSSFileName(outFile.getAbsolutePath());
griddedData.setPathname("///SNOW SUBLIMATION/31OCT2019:0600/01NOV2019:0600//");

GridData gridData = new GridData();
int[] status = new int[1];
griddedData.retrieveGriddedData(true, gridData, status);
if (status[0] < 0) {
Assertions.fail();
}

GridInfo gridInfo = gridData.getGridInfo();
Assertions.assertEquals("M", gridInfo.getDataUnits());
Assertions.assertEquals(DssDataType.PER_CUM.value(), gridInfo.getDataType());
Assertions.assertEquals("31 October 2019, 06:00", gridInfo.getStartTime());
Assertions.assertEquals("1 November 2019, 06:00", gridInfo.getEndTime());
Assertions.assertEquals(-0.090, gridInfo.getMeanValue(), 1E-3);
Assertions.assertEquals(0.001, gridInfo.getMaxValue(), 1E-3);
Assertions.assertEquals(-0.100, gridInfo.getMinValue(), 1E-3);

griddedData.done();
}

@Test
void precipitation() {
if(outFile == null) Assertions.fail();
GriddedData griddedData = new GriddedData();
griddedData.setDSSFileName(outFile.getAbsolutePath());
griddedData.setPathname("///PRECIPITATION/31OCT2019:0600/01NOV2019:0600//");

GridData gridData = new GridData();
int[] status = new int[1];
griddedData.retrieveGriddedData(true, gridData, status);
if (status[0] < 0) {
Assertions.fail();
}

GridInfo gridInfo = gridData.getGridInfo();
Assertions.assertEquals("MM", gridInfo.getDataUnits());
Assertions.assertEquals(DssDataType.PER_CUM.value(), gridInfo.getDataType());
Assertions.assertEquals("31 October 2019, 06:00", gridInfo.getStartTime());
Assertions.assertEquals("1 November 2019, 06:00", gridInfo.getEndTime());
Assertions.assertEquals(-492.912, gridInfo.getMeanValue(), 1E-3);
Assertions.assertEquals(311.8, gridInfo.getMaxValue(), 1E-3);
Assertions.assertEquals(-999.9, gridInfo.getMinValue(), 1E-3);

griddedData.done();
}

@Test
void temperature() {
if(outFile == null) Assertions.fail();
GriddedData griddedData = new GriddedData();
griddedData.setDSSFileName(outFile.getAbsolutePath());
griddedData.setPathname("///TEMPERATURE/31OCT2019:0600///");

GridData gridData = new GridData();
int[] status = new int[1];
griddedData.retrieveGriddedData(true, gridData, status);
if (status[0] < 0) {
Assertions.fail();
}

GridInfo gridInfo = gridData.getGridInfo();
Assertions.assertEquals("DEG C", gridInfo.getDataUnits());
Assertions.assertEquals(DssDataType.INST_VAL.value(), gridInfo.getDataType());
Assertions.assertEquals("31 October 2019, 06:00", gridInfo.getStartTime());
Assertions.assertEquals("31 October 2019, 06:00", gridInfo.getEndTime());
Assertions.assertEquals(-9899.17, gridInfo.getMeanValue(), 1E-3);
Assertions.assertEquals(-0.15, gridInfo.getMaxValue(), 1E-3);
Assertions.assertEquals(-10272.15, gridInfo.getMinValue(), 1E-3);

griddedData.done();
}
}

0 comments on commit 83b1004

Please sign in to comment.