Changeset 10856 in josm for trunk/test
- Timestamp:
- 2016-08-19T22:47:37+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/MapViewStateTest.java
r10462 r10856 7 7 import java.awt.geom.Point2D; 8 8 import java.util.Arrays; 9 import java.util.function.Function; 9 10 10 11 import org.junit.Before; … … 23 24 public class MapViewStateTest { 24 25 25 private static final int WIDTH = 30 0;26 private static final int WIDTH = 301; 26 27 private static final int HEIGHT = 200; 27 28 private MapViewState state; … … 43 44 } 44 45 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 45 61 /** 46 62 * Test {@link MapViewState#getCenter()} returns map view center. … … 48 64 @Test 49 65 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); 62 67 } 63 68 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) { 65 78 assertEquals("x", x, center.getInViewX(), 0.01); 66 79 assertEquals("y", y, center.getInViewY(), 0.01); … … 101 114 @Test 102 115 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); 105 118 106 119 EastNorth eastnorth = p.getEastNorth(); … … 110 123 assertEquals("north", shouldEastNorth.north(), eastnorth.north(), 0.01); 111 124 MapViewPoint reversed = state.getPointFor(shouldEastNorth); 112 assertHasViewCoords(WIDTH / 2 , HEIGHT / 2, reversed);125 assertHasViewCoords(WIDTH / 2d, HEIGHT / 2d, reversed); 113 126 114 127 LatLon latlon = p.getLatLon();
Note:
See TracChangeset
for help on using the changeset viewer.