source: josm/trunk/test/unit/org/openstreetmap/josm/data/BoundsTest.java

Last change on this file was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertFalse;
6import static org.junit.jupiter.api.Assertions.assertTrue;
7
8import java.awt.geom.Rectangle2D;
9
10import org.junit.jupiter.api.Test;
11import org.openstreetmap.josm.data.coor.LatLon;
12
13/**
14 * Unit tests for class {@link Bounds}.
15 */
16class BoundsTest {
17
18 @Test
19 void testCrossing() {
20 Bounds b1 = new Bounds(0, 170, 50, -170);
21 assertTrue(b1.crosses180thMeridian());
22 assertFalse(b1.contains(new LatLon(-10, -180)));
23 assertTrue(b1.contains(new LatLon(0, -180)));
24 assertTrue(b1.contains(new LatLon(50, -180)));
25 assertFalse(b1.contains(new LatLon(60, -180)));
26 assertFalse(b1.contains(new LatLon(-10, 180)));
27 assertTrue(b1.contains(new LatLon(0, 180)));
28 assertTrue(b1.contains(new LatLon(50, 180)));
29 assertFalse(b1.contains(new LatLon(60, 180)));
30
31 Bounds b2 = new Bounds(60, 170, 90, -170);
32 assertFalse(b1.intersects(b2));
33 assertFalse(b2.intersects(b1));
34
35 Bounds b3 = new Bounds(25, 170, 90, -170);
36 assertTrue(b1.intersects(b3));
37 assertTrue(b3.intersects(b1));
38 assertTrue(b2.intersects(b3));
39 assertTrue(b3.intersects(b2));
40
41 b3.extend(b1);
42 assertEquals(b3, new Bounds(0, 170, 90, -170));
43 assertTrue(b1.intersects(b3));
44 assertTrue(b3.intersects(b1));
45 assertTrue(b2.intersects(b3));
46 assertTrue(b3.intersects(b2));
47
48 b3.extend(LatLon.ZERO);
49 assertEquals(b3, new Bounds(0, 0, 90, -170));
50 }
51
52 private static void doTestConstructorNominal(Bounds b) {
53 double eps = 1e-7;
54 assertEquals(1d, b.getMinLat(), eps);
55 assertEquals(2d, b.getMinLon(), eps);
56 assertEquals(3d, b.getMaxLat(), eps);
57 assertEquals(4d, b.getMaxLon(), eps);
58 }
59
60 private static void doTestConstructorPoint(Bounds b) {
61 double eps = 1e-7;
62 assertEquals(1d, b.getMinLat(), eps);
63 assertEquals(2d, b.getMinLon(), eps);
64 assertEquals(1d, b.getMaxLat(), eps);
65 assertEquals(2d, b.getMaxLon(), eps);
66 }
67
68 /**
69 * Unit tests for {@link Bounds#Bounds} - nominal cases.
70 */
71 @Test
72 void testConstructorNominalCases() {
73 doTestConstructorNominal(new Bounds(new LatLon(1d, 2d), new LatLon(3d, 4d)));
74 doTestConstructorNominal(new Bounds(new LatLon(1d, 2d), new LatLon(3d, 4d), true));
75 doTestConstructorNominal(new Bounds(1d, 2d, 3d, 4d));
76 doTestConstructorNominal(new Bounds(1d, 2d, 3d, 4d, true));
77 doTestConstructorNominal(new Bounds(new double[]{1d, 2d, 3d, 4d}));
78 doTestConstructorNominal(new Bounds(new double[]{1d, 2d, 3d, 4d}, true));
79 doTestConstructorNominal(new Bounds(new Bounds(1d, 2d, 3d, 4d)));
80 doTestConstructorNominal(new Bounds(new Rectangle2D.Double(2d, 1d, 2d, 2d)));
81 }
82
83 /**
84 * Unit tests for {@link Bounds#Bounds} - single point cases.
85 */
86 @Test
87 void testConstructorSinglePointCases() {
88 doTestConstructorPoint(new Bounds(new LatLon(1d, 2d)));
89 doTestConstructorPoint(new Bounds(new LatLon(1d, 2d), true));
90 doTestConstructorPoint(new Bounds(1d, 2d, true));
91 }
92}
Note: See TracBrowser for help on using the repository browser.