|
| 1 | +package com.androidplot.xy; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | + |
| 5 | +import java.util.List; |
| 6 | + |
| 7 | +import static junit.framework.Assert.assertEquals; |
| 8 | +import static org.mockito.Mockito.mock; |
| 9 | + |
| 10 | +public class CatmullRomInterpolatorTest { |
| 11 | + |
| 12 | + @Test(expected = IllegalArgumentException.class) |
| 13 | + public void interpolate_invalidPointsPerSegment_throwsIllegalArgumentException() { |
| 14 | + final XYSeries series = mock(XYSeries.class); |
| 15 | + final CatmullRomInterpolator.Params params = |
| 16 | + new CatmullRomInterpolator.Params(1, CatmullRomInterpolator.Type.Centripetal); |
| 17 | + |
| 18 | + new CatmullRomInterpolator().interpolate(series, params); |
| 19 | + } |
| 20 | + |
| 21 | + @Test(expected = IllegalArgumentException.class) |
| 22 | + public void interpolate_twoElementSeries_throwsIllegalArgumentException() { |
| 23 | + final XYSeries series = new SimpleXYSeries(SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "test", 1, 2); |
| 24 | + final CatmullRomInterpolator.Params params = |
| 25 | + new CatmullRomInterpolator.Params(2, CatmullRomInterpolator.Type.Centripetal); |
| 26 | + |
| 27 | + new CatmullRomInterpolator().interpolate(series, params); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void interpolate_threeElementSeriesAndThreePointsPerSegment_producesFivePoints() { |
| 32 | + final XYSeries series = new SimpleXYSeries(SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "test", 1, 2, 3); |
| 33 | + final CatmullRomInterpolator.Params params = |
| 34 | + new CatmullRomInterpolator.Params(3, CatmullRomInterpolator.Type.Centripetal); |
| 35 | + final List<XYCoords> interpolated = new CatmullRomInterpolator().interpolate(series, params); |
| 36 | + |
| 37 | + assertEquals(5, interpolated.size()); |
| 38 | + |
| 39 | + // control points should exactly match input: |
| 40 | + assertEquals(1, interpolated.get(0).y); |
| 41 | + assertEquals(2, interpolated.get(2).y); |
| 42 | + assertEquals(3, interpolated.get(4).y); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void interpolate_threeElementSeriesAndFourPointsPerSegment_producesSavenPoints() { |
| 47 | + final XYSeries series = new SimpleXYSeries(SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "test", 1, 2, 3); |
| 48 | + final CatmullRomInterpolator.Params params = |
| 49 | + new CatmullRomInterpolator.Params(4, CatmullRomInterpolator.Type.Centripetal); |
| 50 | + final List<XYCoords> interpolated = new CatmullRomInterpolator().interpolate(series, params); |
| 51 | + |
| 52 | + assertEquals(7, interpolated.size()); |
| 53 | + |
| 54 | + // control points should exactly match input: |
| 55 | + assertEquals(1, interpolated.get(0).y); |
| 56 | + assertEquals(2, interpolated.get(3).y); |
| 57 | + assertEquals(3, interpolated.get(6).y); |
| 58 | + } |
| 59 | +} |
0 commit comments