Changeset 12029 in josm for trunk/test/unit
- Timestamp:
- 2017-04-30T19:36:36+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/osm/BBoxTest.java
r11272 r12029 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 import static org.junit.Assert.assertEquals; 4 5 import static org.junit.Assert.assertFalse; 5 6 import static org.junit.Assert.assertTrue; … … 68 69 } 69 70 71 /** 72 * Test double constructor which might result in invalid bbox 73 */ 74 @Test 75 public void testDoubleConstructor() { 76 assertTrue(new BBox(1, 2, 3, 4).isValid()); 77 assertFalse(new BBox(Double.NaN, 2, 3, 4).isValid()); 78 assertFalse(new BBox(1, Double.NaN, 3, 4).isValid()); 79 assertFalse(new BBox(1, 2, Double.NaN, 4).isValid()); 80 assertFalse(new BBox(1, 2, 3, Double.NaN).isValid()); 81 } 82 83 /** 84 * Test Node constructor which might result in invalid bbox 85 */ 86 @Test 87 public void testNodeConstructor() { 88 assertTrue(new BBox(new Node(LatLon.NORTH_POLE)).isValid()); 89 assertFalse(new BBox(new Node()).isValid()); 90 } 91 92 /** 93 * Unit test of {@link BBox#add(LatLon)} method. 94 */ 95 @Test 96 public void testAddLatLon() { 97 BBox b = new BBox(); 98 b.add((LatLon) null); 99 b.add(new LatLon(Double.NaN, Double.NaN)); 100 assertFalse(b.isValid()); 101 b.add(LatLon.NORTH_POLE); 102 assertTrue(b.isValid()); 103 assertEquals(LatLon.NORTH_POLE, b.getCenter()); 104 } 105 106 /** 107 * Unit test of {@link BBox#add(double, double)} method. 108 */ 109 @Test 110 public void testAddDouble() { 111 BBox b = new BBox(); 112 b.add(1, Double.NaN); 113 assertFalse(b.isValid()); 114 b.add(Double.NaN, 2); 115 assertFalse(b.isValid()); 116 b.add(1, 2); 117 assertTrue(b.isValid()); 118 assertEquals(new LatLon(2, 1), b.getCenter()); 119 } 120 121 /** 122 * Unit test of {@link BBox#addPrimitive} method. 123 */ 124 @Test 125 public void testAddPrimitive() { 126 BBox b = new BBox(); 127 b.addPrimitive(new Node(LatLon.NORTH_POLE), 0.5); 128 assertEquals(LatLon.NORTH_POLE, b.getCenter()); 129 assertEquals(new LatLon(90.5, -0.5), b.getTopLeft()); 130 assertEquals(new LatLon(89.5, +0.5), b.getBottomRight()); 131 } 132 133 /** 134 * Unit test of {@link BBox#height} and {@link BBox#width} methods. 135 */ 136 @Test 137 public void testHeightWidth() { 138 BBox b1 = new BBox(1, 2, 3, 5); 139 assertEquals(2, b1.width(), 1e-7); 140 assertEquals(3, b1.height(), 1e-7); 141 BBox b2 = new BBox(); 142 assertEquals(0, b2.width(), 1e-7); 143 assertEquals(0, b2.height(), 1e-7); 144 } 145 146 /** 147 * Unit test of {@link BBox#toString} method. 148 */ 149 @Test 150 public void testToString() { 151 assertEquals("[ x: Infinity -> -Infinity, y: Infinity -> -Infinity ]", new BBox().toString()); 152 assertEquals("[ x: 1.0 -> 3.0, y: 2.0 -> 4.0 ]", new BBox(1, 2, 3, 4).toString()); 153 } 70 154 }
Note:
See TracChangeset
for help on using the changeset viewer.