def test_from_bounding_box(self): # Arrange extent1 = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) extent2 = hm.Extent(coords=(hm.Coordinate(0, 0), hm.Coordinate(40, 40))) # Act extent1.from_bounding_box(extent2) # Assert self.assertEqual(extent1.size(), hm.Coordinate(40, 40))
def test_update(self): # Arrange extent1 = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) extent2 = hm.Extent(coords=(hm.Coordinate(0, 0), hm.Coordinate(40, 40))) # Act extent1.update(extent2) # Assert self.assertEqual(extent1.size(), hm.Coordinate(50, 50))
def test_size(self): # Act / Assert extent = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) # Assert self.assertEqual(extent.size(), hm.Coordinate(20, 20))
def test_corners(self): # Arrange extent = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) # Act / Assert self.assertEqual(extent.corners(), (hm.Coordinate(-10, -10), hm.Coordinate(10, 10)))
def test_is_inside(self): # Arrange extent = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) # Act / Assert self.assertTrue(extent.is_inside(hm.Coordinate(1, 1))) self.assertFalse(extent.is_inside(hm.Coordinate(100, 100)))
def test_resize(self): # Arrange extent = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) # Act extent.resize(width=10, height=20) # Assert self.assertEqual(extent.corners(), (hm.Coordinate(-5, -10), hm.Coordinate(5, 10)))
def test_grow(self): # Arrange extent = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) # Act extent.grow(20) # Assert self.assertEqual(extent.corners(), (hm.Coordinate(-30, -30), hm.Coordinate(30, 30)))
def test_init_from_coords(self): # Act extent = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) # Assert self.assertIsNotNone(extent) self.assertIsInstance(extent, hm.Extent) self.assertEqual(str(extent), "-10,-10,10,10") # Assert self.assertIsNotNone(extent) self.assertIsInstance(extent, hm.Extent) self.assertEqual(str(extent), "-10,-10,10,10")
def test_choose_osm_zoom_with_w_h_in_config(self): # Arrange config = hm.Configuration(use_defaults=True) config.width = 400 config.height = 200 config.extent_in = hm.Extent(coords=(hm.LatLon(-10, -10), hm.LatLon(10, 10))) padding = 2 # Act zoom = hm.choose_osm_zoom(config, padding) # Assert self.assertEqual(zoom, 3)
def setup_config(self, iter): map = PIL.Image.open(config["map_img"]) self.map_size = map.size self.hm_config = hm.Configuration() self.hm_config.width = map.size[0] self.hm_config.height = map.size[1] self.hm_config.margin = 0 self.hm_config.zoom = 1 self.hm_config.projection = hm.EquirectangularProjection() self.hm_config.projection.pixels_per_degree = 1 self.hm_config.extent_out = hm.Extent( coords=[hm.Coordinate(c[0], c[1]) for c in [(0, 0), map.size]]) self.hm_config.extent_in = hm.Extent(coords=[ self.hm_config.projection.inverse_project(hm.Coordinate( c[0], c[1])) for c in [(0, 0), map.size] ]) self.hm_config.shapes = iter self.hm_config.decay = 0.5 self.hm_config.kernel = hm.LinearKernel(5) self.hm_config.background_image = map self.hm_config.fill_missing() return config
def test_no_init(self): # Act / Assert with self.assertRaises(ValueError): hm.Extent()