Skip to content

Commit

Permalink
Add tolerance when comparing doubles
Browse files Browse the repository at this point in the history
  • Loading branch information
Tara Drwenski authored and tdrwenski committed Jan 10, 2024
1 parent 3c1afa9 commit 3cd53e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static com.google.common.truth.Truth.assertThat;

public class TestEnhancements {
private static final double TOLERANCE = 1.0e-5;

final static String ENHANCED_FILE = "localContent/testOffset.nc";
final static String NCML_ENHANCED_FILE = "testOffsetWithNcml.nc";
Expand Down Expand Up @@ -73,7 +74,7 @@ private void checkResultWithEnhancements(NetcdfFile netcdfFile, int expectedDiff
final Array values1 = enhancedVar.read();
final Array values2 = orgVar.read();
for (int i = 0; i < values1.getSize(); i++) {
assertThat(values1.getDouble(i)).isEqualTo(values2.getDouble(i) + expectedDiff);
assertThat(values1.getDouble(i)).isWithin(TOLERANCE).of(values2.getDouble(i) + expectedDiff);
}
}
}
4 changes: 2 additions & 2 deletions tds/src/main/java/thredds/core/DatasetManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ public NetcdfFile openNetcdfFile(HttpServletRequest req, HttpServletResponse res

DatasetUrl durl = DatasetUrl.findDatasetUrl(location);
if (useNetcdfJavaBuilders || isLocationObjectStore(location)) {
ncfile = NetcdfDatasets.acquireFile(durl, null);
ncfile = NetcdfDatasets.acquireDataset(durl, null);
} else {
ncfile = NetcdfDataset.acquireFile(durl, null);
ncfile = NetcdfDataset.acquireDataset(durl, null);
}
}

Expand Down

0 comments on commit 3cd53e8

Please sign in to comment.