Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tgrigsby-sc committed Dec 9, 2021
1 parent 0df5608 commit 1e5f868
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,48 +516,60 @@ def _c(z, x, y):


class TestRemoveWrongZoomedFeatures(unittest.TestCase):
def setUp(self):
self.nzoom = 16 # nominal zoom is 16. It's a variable to demonstrate the actual value doesn't matter


def get_test_layers(self):
return [dict(
name="things",
layer_datum="I am a datum",
features=[
(None, dict(name="big thing", min_zoom=10), 123),
(None, dict(name="small thing", min_zoom=16), 234),
(None, dict(name="tiny thing", min_zoom=18), 345),
(None, dict(name="wow so tiny thing", min_zoom=19), 456)
(None, dict(name="big thing", min_zoom=self.nzoom - 6), 123),
(None, dict(name="small thing", min_zoom=self.nzoom), 234),
(None, dict(name="tiny thing", min_zoom=self.nzoom + 2), 345),
(None, dict(name="wow so tiny thing", min_zoom=self.nzoom + 3), 456)
],
padded_bounds="I am padded bounds"
), dict(
name="items",
layer_datum="Yet another datum",
features=[
(None, dict(name="big item", min_zoom=13), 123),
(None, dict(name="small item", min_zoom=15), 234),
(None, dict(name="tiny item", min_zoom=16.999), 345),
(None, dict(name="tiniest item", min_zoom=17), 456)
(None, dict(name="big item", min_zoom=self.nzoom - 3), 123),
(None, dict(name="small item", min_zoom=self.nzoom - 1), 234),
(None, dict(name="tiny item", min_zoom=self.nzoom + 0.999), 345),
(None, dict(name="tiniest item", min_zoom=self.nzoom + 1), 456)
],
padded_bounds="Yet another instance of padded bounds"
)]

def test_nominal_zoom_under_max_untouched(self):
expected = self.get_test_layers()

self.assertEqual(expected, remove_wrong_zoomed_features(self.get_test_layers(), 14, 15, 16))
# here coord zoom is not at the nominal zoom, but it doesn't matter because nominal zoom is less
# than max zoom with changes. Therefore, it should come out the same
self.assertEqual(expected, remove_wrong_zoomed_features(self.get_test_layers(), self.nzoom - 2, self.nzoom - 1,
self.nzoom))

def test_coord_zoom_at_max_zoom_untouched(self):
expected = self.get_test_layers()

self.assertEqual(expected, remove_wrong_zoomed_features(self.get_test_layers(), 16, 16, 16))
# here nominal zoom is equal to max_zoom_with_changes, but the coord_zoom is too, so no changes here
self.assertEqual(expected, remove_wrong_zoomed_features(self.get_test_layers(), self.nzoom, self.nzoom,
self.nzoom))

def test_higher_min_zoom_features_removed_when(self):
def test_higher_min_zoom_features_removed_when_below_nominal_zoom(self):
expected = self.get_test_layers()

# remove the last two items from the things layer
expected[0]['features']=expected[0]['features'][0:2]
# remove the last item from the items layer
expected[1]['features']=expected[1]['features'][0:3]
# remove the last two items from the things layer (whose min_zoom levels are 17 or greater)
expected[0]['features'] = expected[0]['features'][0:2]
# remove the last item from the items layer (whose min_zoom level is 17 or greater)
expected[1]['features'] = expected[1]['features'][0:3]

self.assertEqual(expected, remove_wrong_zoomed_features(self.get_test_layers(), 15, 16, 16))
# here, coord zoom is less than nominal zoom AND nominal zoom is equal to max_zoom_with_changes. We should
# remove the features with min_zoom above (nominal_zoom + 1)
self.assertEqual(expected, remove_wrong_zoomed_features(self.get_test_layers(), self.nzoom - 1, self.nzoom,
self.nzoom))


def _only_zoom(ctx, zoom):
Expand Down

0 comments on commit 1e5f868

Please sign in to comment.