Пример #1
0
 @Test
 public void testPointAcquisition() {
   assertArrayEquals(
       dummyPoints,
       spyRouteDrawer.getRoutePoints(
           dummyRouteDescription, dummyMapData, 0, 0, new Dimension(), new Dimension()));
   for (int i = 0; i < 10; i++) {
     assertArrayEquals(
         dummyPoints,
         spyRouteDrawer.getRoutePoints(
             dummyRouteDescription,
             dummyMapData,
             randomInt(),
             randomInt(),
             new Dimension(),
             new Dimension()));
     assertArrayEquals(
         dummyPoints,
         spyRouteDrawer.getRoutePoints(
             dummyRouteDescription,
             dummyMapData,
             0,
             0,
             new Dimension(randomInt(1000, 100), randomInt(1000, 100)),
             new Dimension()));
     final int randX = randomInt(1000, 0);
     assertEquals(
         new Point(randX, 0),
         MapRouteDrawer.getPointOnMap(
             new Point(randX, 0), randX, 0, new Dimension(randX, 0), new Dimension()));
   }
 }
Пример #2
0
 @Test
 public void testPointSplitting() {
   final double[] xCoords = new double[] {0, 100, 0};
   final double[] yCoords = new double[] {0, 0, 100};
   assertArrayEquals(xCoords, spyRouteDrawer.getValues(dummyPoints, point -> point.getX()), 0);
   assertArrayEquals(yCoords, spyRouteDrawer.getValues(dummyPoints, point -> point.getY()), 0);
 }
Пример #3
0
 @Test
 public void testIndex() {
   assertArrayEquals(spyRouteDrawer.createParameterizedIndex(new Point[] {}), new double[] {}, 0);
   assertEquals(dummyIndex.length, dummyPoints.length);
   // Not sure whether it makes sense to include a Test for specific values
   // The way the index is being calculated may change to a better System
   // Check the link for more information
   // http://stackoverflow.com/a/37370620/5769952
 }
Пример #4
0
 @Test
 public void testCurve() {
   final double[] testYValues = new double[] {20, 40, 90};
   final PolynomialSplineFunction testFunction =
       new SplineInterpolator().interpolate(dummyIndex, testYValues);
   final double[] coords = spyRouteDrawer.getCoords(testFunction, dummyIndex);
   final double stepSize =
       testFunction.getKnots()[testFunction.getKnots().length - 1] / coords.length;
   assertEquals(testYValues[0] * stepSize, coords[(int) Math.round(dummyIndex[0])], 1);
   assertEquals(testYValues[1] * stepSize, coords[(int) Math.round(dummyIndex[1])], 1);
   assertEquals(testYValues[2] * stepSize, coords[(int) Math.round(dummyIndex[2])], 1);
   // TODO change the calculation so that delta = 0;
 }
Пример #5
0
  @Test
  public void testCorrectParameterHandling() {
    // Should not throw any exception - should do nothing
    spyRouteDrawer.drawRoute(null, null, null, null, null);
    final MapPanel mockedMapPanel = mock(MapPanel.class);
    when(mockedMapPanel.getXOffset()).thenReturn(0);
    when(mockedMapPanel.getYOffset()).thenReturn(0);
    when(mockedMapPanel.getScale()).thenReturn(0.0);
    final Shape mockShape = mock(Shape.class);
    final Graphics2D mockGraphics = mock(Graphics2D.class);
    when(mockShape.contains(any(Point2D.class))).thenReturn(true);
    when(mockGraphics.getClip()).thenReturn(mockShape);
    spyRouteDrawer.drawRoute(
        mockGraphics, dummyRouteDescription, mockedMapPanel, dummyMapData, "2");
    verify(mockGraphics, atLeastOnce()).draw(any(Line2D.class));
    verify(mockedMapPanel).getXOffset(); // Those methods are needed
    verify(mockedMapPanel).getYOffset();
    verify(mockedMapPanel).getScale();

    verify(dummyRouteDescription, times(2)).getRoute();
    verify(dummyRouteDescription.getRoute(), atLeastOnce()).getAllTerritories();
  }
Пример #6
0
public class TestRoute {
  private final MapRouteDrawer spyRouteDrawer = spy(new MapRouteDrawer());
  private final Point[] dummyPoints =
      new Point[] {new Point(0, 0), new Point(100, 0), new Point(0, 100)};
  private final double[] dummyIndex = spyRouteDrawer.createParameterizedIndex(dummyPoints);
  private final Route dummyRoute = spy(new Route());
  private final MapData dummyMapData = mock(MapData.class);
  private final RouteDescription dummyRouteDescription =
      spy(new RouteDescription(dummyRoute, dummyPoints[0], dummyPoints[2], null));

  @Before
  public void setUp() {
    dummyRoute.add(
        mock(
            Territory.class)); // This will be overridden with the startPoint, since it's the origin
    // territory
    dummyRoute.add(mock(Territory.class));
    when(dummyMapData.getCenter(any(Territory.class))).thenReturn(dummyPoints[1]);
  }

  @Test
  public void testIndex() {
    assertArrayEquals(spyRouteDrawer.createParameterizedIndex(new Point[] {}), new double[] {}, 0);
    assertEquals(dummyIndex.length, dummyPoints.length);
    // Not sure whether it makes sense to include a Test for specific values
    // The way the index is being calculated may change to a better System
    // Check the link for more information
    // http://stackoverflow.com/a/37370620/5769952
  }

  @Test
  public void testCurve() {
    final double[] testYValues = new double[] {20, 40, 90};
    final PolynomialSplineFunction testFunction =
        new SplineInterpolator().interpolate(dummyIndex, testYValues);
    final double[] coords = spyRouteDrawer.getCoords(testFunction, dummyIndex);
    final double stepSize =
        testFunction.getKnots()[testFunction.getKnots().length - 1] / coords.length;
    assertEquals(testYValues[0] * stepSize, coords[(int) Math.round(dummyIndex[0])], 1);
    assertEquals(testYValues[1] * stepSize, coords[(int) Math.round(dummyIndex[1])], 1);
    assertEquals(testYValues[2] * stepSize, coords[(int) Math.round(dummyIndex[2])], 1);
    // TODO change the calculation so that delta = 0;
  }

  @Test
  public void testPointSplitting() {
    final double[] xCoords = new double[] {0, 100, 0};
    final double[] yCoords = new double[] {0, 0, 100};
    assertArrayEquals(xCoords, spyRouteDrawer.getValues(dummyPoints, point -> point.getX()), 0);
    assertArrayEquals(yCoords, spyRouteDrawer.getValues(dummyPoints, point -> point.getY()), 0);
  }

  @Test
  public void testPointAcquisition() {
    assertArrayEquals(
        dummyPoints,
        spyRouteDrawer.getRoutePoints(
            dummyRouteDescription, dummyMapData, 0, 0, new Dimension(), new Dimension()));
    for (int i = 0; i < 10; i++) {
      assertArrayEquals(
          dummyPoints,
          spyRouteDrawer.getRoutePoints(
              dummyRouteDescription,
              dummyMapData,
              randomInt(),
              randomInt(),
              new Dimension(),
              new Dimension()));
      assertArrayEquals(
          dummyPoints,
          spyRouteDrawer.getRoutePoints(
              dummyRouteDescription,
              dummyMapData,
              0,
              0,
              new Dimension(randomInt(1000, 100), randomInt(1000, 100)),
              new Dimension()));
      final int randX = randomInt(1000, 0);
      assertEquals(
          new Point(randX, 0),
          MapRouteDrawer.getPointOnMap(
              new Point(randX, 0), randX, 0, new Dimension(randX, 0), new Dimension()));
    }
  }

  private static int randomInt(int max, int min) {
    if (max - min < 0) {
      final int oldMax = max;
      max = min;
      min = oldMax;
    }
    return (int) ((Math.random() * (max - min)) + min);
  }

  private static int randomInt() {
    return randomInt(1000, -1000);
  }

  @Test
  public void testCorrectParameterHandling() {
    // Should not throw any exception - should do nothing
    spyRouteDrawer.drawRoute(null, null, null, null, null);
    final MapPanel mockedMapPanel = mock(MapPanel.class);
    when(mockedMapPanel.getXOffset()).thenReturn(0);
    when(mockedMapPanel.getYOffset()).thenReturn(0);
    when(mockedMapPanel.getScale()).thenReturn(0.0);
    final Shape mockShape = mock(Shape.class);
    final Graphics2D mockGraphics = mock(Graphics2D.class);
    when(mockShape.contains(any(Point2D.class))).thenReturn(true);
    when(mockGraphics.getClip()).thenReturn(mockShape);
    spyRouteDrawer.drawRoute(
        mockGraphics, dummyRouteDescription, mockedMapPanel, dummyMapData, "2");
    verify(mockGraphics, atLeastOnce()).draw(any(Line2D.class));
    verify(mockedMapPanel).getXOffset(); // Those methods are needed
    verify(mockedMapPanel).getYOffset();
    verify(mockedMapPanel).getScale();

    verify(dummyRouteDescription, times(2)).getRoute();
    verify(dummyRouteDescription.getRoute(), atLeastOnce()).getAllTerritories();
  }
}