def setUp(self): self.battery = [] stationFoo = pybikes.BikeShareStation(0) stationFoo.name = 'foo' stationFoo.latitude = 40.0149856 stationFoo.longitude = -105.2705455 stationFoo.bikes = 10 stationFoo.free = 20 stationFoo.extra = { 'foo': 'fuzz' } stationBar = pybikes.BikeShareStation(1) stationBar.name = 'foo' stationBar.latitude = 19.4326077 stationBar.longitude = -99.13320799999997 stationBar.bikes = 10 stationBar.free = 20 stationBar.extra = { 'bar': 'baz' } self.battery.append({ 'instance': stationFoo, 'hash': 'e1aea428a04db6a77c4a1a091edcfcb6' }) self.battery.append({ 'instance': stationBar, 'hash': '065d7bb95e6c9079190334ee0d320c72' })
def test_filter_bounds(self): """ Tests that filter_bounds utils function correctly filters stations out of a given number of bounds. Function must accept multiple lists of points to form polygons (4 for a box, oc).""" in_bounds = [ # First bound pybikes.BikeShareStation(latitude=1.1, longitude=1.1), pybikes.BikeShareStation(latitude=2.2, longitude=2.2), pybikes.BikeShareStation(latitude=3.3, longitude=3.3), pybikes.BikeShareStation(latitude=4.4, longitude=4.4), # Second bound pybikes.BikeShareStation(latitude=21.0, longitude=21.0), pybikes.BikeShareStation(latitude=22.0, longitude=22.0), pybikes.BikeShareStation(latitude=23.0, longitude=23.0), pybikes.BikeShareStation(latitude=24.0, longitude=24.0), ] off_bounds = [ pybikes.BikeShareStation(latitude=11.1, longitude=11.1), pybikes.BikeShareStation(latitude=12.2, longitude=12.2), pybikes.BikeShareStation(latitude=13.3, longitude=13.3), pybikes.BikeShareStation(latitude=14.4, longitude=14.4), ] bounds = ( [[0.0, 0.0], [5.0, 0.0], [5.0, 5.0], [0.0, 5.0]], [ # This bounding box is a set of two points, NE, SW [20.0, 25.0], [25.0, 20.0], ]) result = pybikes.utils.filter_bounds(in_bounds + off_bounds, None, *bounds) self.assertEqual(in_bounds, list(result))