|
| 1 | +package ucar.nc2.ft2.coverage; |
| 2 | + |
| 3 | +import static com.google.common.truth.Truth.assertThat; |
| 4 | + |
| 5 | +import java.util.Arrays; |
| 6 | +import java.util.List; |
| 7 | +import org.junit.Test; |
| 8 | +import org.junit.runner.RunWith; |
| 9 | +import org.junit.runners.Parameterized; |
| 10 | +import ucar.ma2.DataType; |
| 11 | +import ucar.ma2.InvalidRangeException; |
| 12 | +import ucar.ma2.Range; |
| 13 | +import ucar.nc2.constants.AxisType; |
| 14 | +import ucar.nc2.ft2.coverage.CoverageCoordAxis.Spacing; |
| 15 | + |
| 16 | +@RunWith(Parameterized.class) |
| 17 | +public class TestCoordAxisHelper { |
| 18 | + |
| 19 | + @Parameterized.Parameters(name = "{0}, {1}") |
| 20 | + public static List<Object[]> getTestParameters() { |
| 21 | + return Arrays.asList( |
| 22 | + |
| 23 | + new Object[] {Spacing.regularPoint, new double[] {0.0, 10.0, 20.0, 30.0, 40.0}}, |
| 24 | + new Object[] {Spacing.irregularPoint, new double[] {0.0, 5.0, 20.0, 30.0, 40.0}}, |
| 25 | + new Object[] {Spacing.regularInterval, new double[] {0.0, 10.0, 20.0, 30.0, 40.0}}, |
| 26 | + new Object[] {Spacing.contiguousInterval, new double[] {0.0, 5.0, 20.0, 30.0, 40.0}}, |
| 27 | + new Object[] {Spacing.discontiguousInterval, new double[] {0.0, 0.0, 20.0, 30.0, 40.0, 40.0, 50.0, 50.0}} |
| 28 | + |
| 29 | + ); |
| 30 | + } |
| 31 | + |
| 32 | + private final Spacing spacing; |
| 33 | + private final double[] values; |
| 34 | + |
| 35 | + public TestCoordAxisHelper(Spacing spacing, double[] values) { |
| 36 | + this.spacing = spacing; |
| 37 | + this.values = values; |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void shouldSubsetAxisByRange() throws InvalidRangeException { |
| 42 | + final AxisType axisType = AxisType.Time; |
| 43 | + final double resolution = values[1] - values[0]; |
| 44 | + |
| 45 | + final CoverageCoordAxisBuilder coverageCoordAxisBuilder = new CoverageCoordAxisBuilder("name", "unit", |
| 46 | + "description", DataType.DOUBLE, axisType, null, CoverageCoordAxis.DependenceType.independent, null, spacing, |
| 47 | + values.length, values[0], values[values.length - 1], resolution, values, null); |
| 48 | + final CoverageCoordAxis1D coverageCoordAxis = new CoverageCoordAxis1D(coverageCoordAxisBuilder); |
| 49 | + final CoordAxisHelper coordAxisHelper = new CoordAxisHelper(coverageCoordAxis); |
| 50 | + |
| 51 | + final Range subsetRange = new Range(1, 3); |
| 52 | + final CoverageCoordAxisBuilder subsetBuilder = coordAxisHelper.subsetByIndex(subsetRange); |
| 53 | + assertThat(subsetBuilder).isNotNull(); |
| 54 | + assertThat(subsetBuilder.axisType).isEqualTo(axisType); |
| 55 | + assertThat(subsetBuilder.startValue).isEqualTo(values[subsetRange.first()]); |
| 56 | + assertThat(subsetBuilder.endValue).isEqualTo(values[subsetRange.last()]); |
| 57 | + |
| 58 | + if (spacing == Spacing.regularPoint || spacing == Spacing.regularInterval) { |
| 59 | + assertThat(subsetBuilder.values).isNull(); |
| 60 | + } else { |
| 61 | + assertThat(subsetBuilder.values).isNotNull(); |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments