Skip to content

Commit

Permalink
fix the flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
matakleo committed Jun 25, 2024
1 parent ece1779 commit 81baa02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion cdm/core/src/main/java/ucar/nc2/filter/Classifier.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ucar.nc2.filter;

import static ucar.ma2.MAMath.nearlyEquals;
import ucar.ma2.Array;
import ucar.ma2.IndexIterator;
import ucar.nc2.Variable;
import ucar.nc2.constants.CDM;
import ucar.nc2.Attribute;
import ucar.nc2.util.Misc;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -84,7 +86,7 @@ public int classifyArray(double val) {

public int classifyArrayAttribute(double val) {
for (int[] rule : rules) {
if (val > rule[0] && val <= rule[1]) {
if (val > rule[0] && val <= rule[1] + ucar.nc2.util.Misc.defaultMaxRelativeDiffFloat) {
return rule[2]; // Return the matched rule's value
}
}
Expand Down
16 changes: 8 additions & 8 deletions cdm/core/src/test/data/ncml/enhance/testClassifier.ncml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
<values>1 2 3 4 5</values>
</variable>

<variable name="intNegatives" shape="5" type="int">
<attribute name="classify"/>
<values>-1.0 -2.0 -3.0 -4.0 -5.0</values>
</variable>
<variable name="intMix" shape="5" type="int">
<attribute name="classify"/>
<values>1.0 -2.0 0.0 4.0 -5.0</values>
</variable>
<variable name="intNegatives" shape="5" type="int">
<attribute name="classify"/>
<values>-1 -2 -3 -4 -5</values>
</variable>
<variable name="intMix" shape="5" type="int">
<attribute name="classify"/>
<values>1 -2 0 4 -5</values>
</variable>



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void testEnhanceClassifier_floats() throws IOException {
assertThat(floatMix.getDataType()).isEqualTo(DataType.FLOAT);
assertThat(floatMix.attributes().hasAttribute("classify")).isTrue();
Array datafloatsMix = floatMix.read();
// assertThat(datafloatsMix).isEqualTo(DATA_mixNumbers);
assertThat(nearlyEquals(datafloatsMix, DATA_mixNumbers)).isTrue();

}
Expand Down Expand Up @@ -128,6 +129,8 @@ public void testEnhanceClassifier_classification() throws IOException {
assertThat(!Classify_Specsx.attributes().isEmpty()).isTrue();
Array Data = Classify_Specsx.read();
Classifier classifier = Classifier.createFromVariable(Classify_Specsx);
// List<Attribute> Whatever = Classify_Specsx.getAttributes();
// Classifier classifier = new Classifier(Whatever);
int[] ClassifiedArray = classifier.classifyWithAttributes(Data);
assertThat(nearlyEquals(Array.makeFromJavaArray(ClassifiedArray), CLASSIFICATION_TEST)).isTrue();

Expand Down

0 comments on commit 81baa02

Please sign in to comment.