Changeset 10856 in josm for trunk/test


Ignore:
Timestamp:
2016-08-19T22:47:37+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #13375 - Fix icon rendering (patch by michael2402) - gsoc-core + add unit test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/MapViewStateTest.java

    r10462 r10856  
    77import java.awt.geom.Point2D;
    88import java.util.Arrays;
     9import java.util.function.Function;
    910
    1011import org.junit.Before;
     
    2324public class MapViewStateTest {
    2425
    25     private static final int WIDTH = 300;
     26    private static final int WIDTH = 301;
    2627    private static final int HEIGHT = 200;
    2728    private MapViewState state;
     
    4344    }
    4445
     46    private void doTestGetCenter(Function<MapViewState, MapViewPoint> getter, Function<Integer, Double> divider) {
     47        MapViewPoint center = getter.apply(state);
     48        assertHasViewCoords(divider.apply(WIDTH), divider.apply(HEIGHT), center);
     49
     50        MapViewState newState = state.movedTo(center, new EastNorth(3, 4));
     51
     52        // state should not change, but new state should.
     53        center = getter.apply(state);
     54        assertHasViewCoords(divider.apply(WIDTH), divider.apply(HEIGHT), center);
     55
     56        center = getter.apply(newState);
     57        assertEquals("east", 3, center.getEastNorth().east(), 0.01);
     58        assertEquals("north", 4, center.getEastNorth().north(), 0.01);
     59    }
     60
    4561    /**
    4662     * Test {@link MapViewState#getCenter()} returns map view center.
     
    4864    @Test
    4965    public void testGetCenter() {
    50         MapViewPoint center = state.getCenter();
    51         assertHasViewCoords(WIDTH / 2, HEIGHT / 2, center);
    52 
    53         MapViewState newState = state.movedTo(center, new EastNorth(3, 4));
    54 
    55         // state should not change, but new state should.
    56         center = state.getCenter();
    57         assertHasViewCoords(WIDTH / 2, HEIGHT / 2, center);
    58 
    59         center = newState.getCenter();
    60         assertEquals("east", 3, center.getEastNorth().east(), 0.01);
    61         assertEquals("north", 4, center.getEastNorth().north(), 0.01);
     66        doTestGetCenter(s -> s.getCenter(), t -> t / 2d);
    6267    }
    6368
    64     private void assertHasViewCoords(double x, double y, MapViewPoint center) {
     69    /**
     70     * Test {@link MapViewState#getCenterAtPixel()} returns map view center.
     71     */
     72    @Test
     73    public void testGetCenterAtPixel() {
     74        doTestGetCenter(s -> s.getCenterAtPixel(), t -> (double) (t / 2));
     75    }
     76
     77    private static void assertHasViewCoords(double x, double y, MapViewPoint center) {
    6578        assertEquals("x", x, center.getInViewX(), 0.01);
    6679        assertEquals("y", y, center.getInViewY(), 0.01);
     
    101114    @Test
    102115    public void testPointConversions() {
    103         MapViewPoint p = state.getForView(WIDTH / 2, HEIGHT / 2);
    104         assertHasViewCoords(WIDTH / 2, HEIGHT / 2, p);
     116        MapViewPoint p = state.getForView(WIDTH / 2d, HEIGHT / 2d);
     117        assertHasViewCoords(WIDTH / 2d, HEIGHT / 2d, p);
    105118
    106119        EastNorth eastnorth = p.getEastNorth();
     
    110123        assertEquals("north", shouldEastNorth.north(), eastnorth.north(), 0.01);
    111124        MapViewPoint reversed = state.getPointFor(shouldEastNorth);
    112         assertHasViewCoords(WIDTH / 2, HEIGHT / 2, reversed);
     125        assertHasViewCoords(WIDTH / 2d, HEIGHT / 2d, reversed);
    113126
    114127        LatLon latlon = p.getLatLon();
Note: See TracChangeset for help on using the changeset viewer.