Ejemplo n.º 1
0
    def test_results_are_not_empty(self):
        locator = GeohashLocator(self.shopLocations)
        radius = 1000

        searchResults = locator.Search(self.origin.Latitude,
                                       self.origin.Longitude, radius)

        self.assertGreater(len(searchResults), 0)
Ejemplo n.º 2
0
    def test_results_are_empty_when_none_in_range(self):
        locator = GeohashLocator(self.shopLocations)
        radius = 1000

        searchResults = locator.Search(self.origin.Latitude + 5,
                                       self.origin.Longitude + 5, radius)

        self.assertEqual(len(searchResults), 0)
Ejemplo n.º 3
0
    def test_result_contains_known_location(self):
        locator = GeohashLocator(self.shopLocations)
        radius = 10  #use a small radius to get as few as possible

        searchResults = locator.Search(self.origin.Latitude,
                                       self.origin.Longitude, radius)
        self.assertGreater(len(searchResults), 0)

        contains = False
        for item in searchResults:
            if (item.Location.Latitude
                    == self.origin.Latitude) and (item.Location.Longitude
                                                  == self.origin.Longitude):
                contains = True
                break

        self.assertTrue(contains)
Ejemplo n.º 4
0
    def test_results_contain_all_items_within_range(self):

        locator = GeohashLocator(self.shopLocations)
        radius = 1000

        geohashSearchResults = locator.Search(self.origin.Latitude,
                                              self.origin.Longitude, radius)
        hashSearchResultCount = len(geohashSearchResults)
        self.assertGreater(hashSearchResultCount, 0)

        bruteforceResults = []
        for item in self.shopLocations:
            distance = CoordinateHelper.GetDistanceMeters(
                self.origin, item.Location)
            if distance <= radius:
                bruteforceResults.append(item)
        bruteforceResultCount = len(bruteforceResults)

        self.assertGreaterEqual(hashSearchResultCount, bruteforceResultCount)

        self.assertTrue(
            set(bruteforceResults).issubset(set(geohashSearchResults)))
Ejemplo n.º 5
0
    def test_search_returns_empty_when_maximumItemCount_is_zero(self):
        #Todo: use mocking for supplying objects
        basicLocator = BasicLocator(self.shopLocations)
        geohashLocator = GeohashLocator(self.shopLocations)
        locator = HybridLocator(geohashLocator, basicLocator)
        provider = SearchProvider(locator)
        radius = 1000

        searchResults = provider.Search(self.origin.Latitude,
                                        self.origin.Longitude, radius, None, 0)

        resultCount = len(searchResults)
        self.assertEqual(resultCount, 0)
Ejemplo n.º 6
0
    def test_search_returns_results_when_tags_null(self):
        #Todo: use mocking for supplying objects
        basicLocator = BasicLocator(self.shopLocations)
        geohashLocator = GeohashLocator(self.shopLocations)
        locator = HybridLocator(geohashLocator, basicLocator)
        provider = SearchProvider(locator)
        radius = 1000

        searchResults = provider.Search(self.origin.Latitude,
                                        self.origin.Longitude, radius, None,
                                        10)

        resultCount = len(searchResults)
        self.assertGreater(resultCount, 0)
Ejemplo n.º 7
0
    def test_search_returns_requested_count_of_results(self):
        #Todo: use mocking for supplying objects
        basicLocator = BasicLocator(self.shopLocations)
        geohashLocator = GeohashLocator(self.shopLocations)
        locator = HybridLocator(geohashLocator, basicLocator)
        provider = SearchProvider(locator)
        radius = 1000

        count = 5
        searchResults = provider.Search(self.origin.Latitude,
                                        self.origin.Longitude, radius, None,
                                        count)

        resultCount = len(searchResults)
        self.assertEqual(resultCount, count)
Ejemplo n.º 8
0
    def test_search_returns_empty_when_no_matching_tags(self):
        #Todo: use mocking for supplying objects
        basicLocator = BasicLocator(self.shopLocations)
        geohashLocator = GeohashLocator(self.shopLocations)
        locator = HybridLocator(geohashLocator, basicLocator)
        provider = SearchProvider(locator)
        radius = 1000

        tags = ["---"]
        searchResults = provider.Search(self.origin.Latitude,
                                        self.origin.Longitude, radius,
                                        set(tags), 10)

        resultCount = len(searchResults)
        self.assertEqual(resultCount, 0)
Ejemplo n.º 9
0
    def test_search_returns_all_elements_when_requested_count_is_more_than_element_count(
            self):
        #Todo: use mocking for supplying objects
        basicLocator = BasicLocator(self.shopLocations)
        geohashLocator = GeohashLocator(self.shopLocations)
        locator = HybridLocator(geohashLocator, basicLocator)
        provider = SearchProvider(locator)
        radius = 5000

        count = 50000
        searchResults = provider.Search(self.origin.Latitude,
                                        self.origin.Longitude, radius, None,
                                        count)

        totalCount = len(self.shopLocations)
        resultCount = len(searchResults)
        self.assertEqual(resultCount, totalCount)
Ejemplo n.º 10
0
    def test_search_returns_only_results_with_specified_tags(self):
        #Todo: use mocking for supplying objects
        basicLocator = BasicLocator(self.shopLocations)
        geohashLocator = GeohashLocator(self.shopLocations)
        locator = HybridLocator(geohashLocator, basicLocator)
        provider = SearchProvider(locator)
        radius = 1000

        tags = ["tag1", "---"]
        searchResults = provider.Search(self.origin.Latitude,
                                        self.origin.Longitude, radius,
                                        set(tags), 10)

        resultCount = len(searchResults)
        self.assertGreater(resultCount, 0)

        for element in searchResults:
            self.assertTrue(tags[0] in element.Shop.tags)
Ejemplo n.º 11
0
    def test_search_returns_known_item_when_location_is_not_edge(self):
        #Todo: use mocking for supplying objects and testing method calls.
        basicLocator = BasicLocator(self.shopLocations)
        geohashLocator = GeohashLocator(self.shopLocations)
        locator = HybridLocator(geohashLocator, basicLocator)
        radius = 1000

        searchResults = locator.Search(self.origin.Latitude,
                                       self.origin.Longitude, radius)

        resultCount = len(searchResults)
        self.assertGreater(resultCount, 0)

        contains = False
        for item in searchResults:
            if (item.Location.Latitude
                    == self.origin.Latitude) and (item.Location.Longitude
                                                  == self.origin.Longitude):
                contains = True
                break

        self.assertTrue(contains)
Ejemplo n.º 12
0
    def test_search_raises_when_negative_coordinates(self):
        locator = GeohashLocator(self.shopLocations)
        radius = 1000

        with self.assertRaises(ValueError):
            locator.Search(-1000, -1000, radius)
Ejemplo n.º 13
0
    def test_constructor_raises_when_container_is_null(self):

        with self.assertRaises(ValueError):
            GeohashLocator(None)
Ejemplo n.º 14
0
    def test_search_raises_when_radius_negative(self):
        locator = GeohashLocator(self.shopLocations)
        radius = -1

        with self.assertRaises(ValueError):
            locator.Search(self.origin.Latitude, self.origin.Longitude, radius)