Skip to content

Commit

Permalink
finish tests
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyajohnson committed Mar 28, 2023
1 parent 676d88b commit a00821a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public DataType getOutType() {
}

public Number convertUnsigned(Number value) {
Number newVal = DataType.widenNumberIfNegative(value);
return DataType.widenNumberIfNegative(value);
}

Expand Down
20 changes: 18 additions & 2 deletions cdm/core/src/test/java/ucar/nc2/filter/TestEnhancements.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class TestEnhancements {
private static final float FILL_VALUE = 150;
private static float[] missingData = new float[]{90, 100, Float.NaN, 120, 130, 140, 150, 190, 200, 210};

private static final Short SIGNED_SCALED_MAX = -126;
private static final Short SIGNED_SCALED_FILL_VALUE = -128;

@ClassRule
public static final TemporaryFolder tempFolder = new TemporaryFolder();

Expand Down Expand Up @@ -63,6 +66,15 @@ public static void setUp() throws IOException , InvalidRangeException {
.addAttribute(Attribute.builder(CDM.VALID_RANGE).setValues(range).build())
.addAttribute(Attribute.builder(CDM.FILL_VALUE).setNumericValue(FILL_VALUE, true).build());

// unsigned, scaled/offset, and missing value
Array enhanceAllArray = Array.factory(DataType.SHORT, new int[]{data_len}, signedShorts);
builder.addVariable("enhanceAll", DataType.SHORT, "dim")
.addAttribute(new Attribute(CDM.UNSIGNED, "true"))
.addAttribute(new Attribute(CDM.SCALE_FACTOR, .1))
.addAttribute(new Attribute(CDM.ADD_OFFSET, 10))
.addAttribute(new Attribute(CDM.VALID_MAX, SIGNED_SCALED_MAX))
.addAttribute(new Attribute(CDM.FILL_VALUE, SIGNED_SCALED_FILL_VALUE));

// write data
NetcdfFormatWriter writer = builder.build();
writer.write(writer.findVariable("signedVar"), new int[1], signedData);
Expand All @@ -71,6 +83,7 @@ public static void setUp() throws IOException , InvalidRangeException {
writer.write(writer.findVariable("validMin"), new int[1], missingDataArray);
writer.write(writer.findVariable("validMinMax"), new int[1], missingDataArray);
writer.write(writer.findVariable("validRange"), new int[1], missingDataArray);
writer.write(writer.findVariable("enhanceAll"), new int[1], enhanceAllArray);
writer.close();
ncd = NetcdfDatasets.openDataset(filePath);
}
Expand Down Expand Up @@ -126,7 +139,10 @@ public void testConvertMissing() throws IOException {
}

@Test
public void testCombinedEnhancements() {

public void testCombinedEnhancements() throws IOException {
int[] expected = new int[]{1240, 1250, 1260, 1270, 1280, 0, 1278, 1260, 0, 0};
Variable v = ncd.findVariable("enhanceAll");
Array data = v.read();
assertThat((int[])data.copyTo1DJavaArray()).isEqualTo(expected);
}
}

0 comments on commit a00821a

Please sign in to comment.