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

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

        self.assertEqual(len(searchResults), 0)
Ejemplo n.º 2
0
    def test_results_are_not_empty(self):
        locator = BasicLocator(self.shopLocations)
        radius = 1000

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

        self.assertGreater(len(searchResults), 0)
Ejemplo n.º 3
0
    def test_results_are_within_range(self):

        locator = BasicLocator(self.shopLocations)
        radius = 1000

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

        for item in searchResults:
            distance = CoordinateHelper.GetDistanceMeters(
                self.origin, item.Location)
            self.assertLessEqual(distance, radius)
Ejemplo n.º 4
0
    def test_result_contains_known_location(self):
        locator = BasicLocator(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.º 5
0
    def test_geohashLocator_used_when_searching_in_non_edge_location(self):
        #Todo: use mocking for supplying objects and testing method calls. For now just uses an exception for telling if a member was accessed
        basicLocator = BasicLocator(self.shopLocations)
        geohashLocator = None
        locator = HybridLocator(geohashLocator, basicLocator)
        radius = 1000

        with self.assertRaises(AttributeError):
            #call will throw an exception if geohashLocator is used
            locator.Search(self.origin.Latitude, self.origin.Longitude, radius)
Ejemplo n.º 6
0
    def test_only_basicLocator_used_when_searching_close_to_primemeridian(
            self):
        #Todo: use mocking for supplying objects and testing method calls. For now just uses an exception for telling if a member was accessed
        basicLocator = BasicLocator(self.shopLocations)
        geohashLocator = None
        locator = HybridLocator(geohashLocator, basicLocator)
        radius = 1000

        #call will throw an exception if geohashLocator is used
        locator.Search(0, 0, radius)
Ejemplo n.º 7
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.º 8
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.º 9
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.º 10
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.º 11
0
    def test_search_returns_known_item_when_location_is_edge(self):
        #Todo: use mocking for supplying objects and testing method calls.
        basicLocator = BasicLocator(self.shopLocations)
        geohashLocator = None
        locator = HybridLocator(geohashLocator, basicLocator)
        radius = 1000

        #call will throw an exception if geohashLocator is used
        searchResults = locator.Search(self.origin.Latitude, 0, radius)

        resultCount = len(searchResults)
        self.assertEqual(resultCount, 1)

        item = searchResults[0]
        self.assertEqual(item.Location.Latitude, self.origin.Latitude)
        self.assertEqual(item.Location.Longitude, 0)
Ejemplo n.º 12
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.º 13
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.º 14
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.º 15
0
    def test_search_raises_when_radius_negative(self):
        locator = BasicLocator(self.shopLocations)
        radius = -1

        with self.assertRaises(ValueError):
            locator.Search(self.origin.Latitude, self.origin.Longitude, radius)
Ejemplo n.º 16
0
    def test_search_raises_when_container_is_null(self):

        with self.assertRaises(ValueError):
            BasicLocator(None)
Ejemplo n.º 17
0
 def test_search_raises_when_negative_coordinates(self):
     locator = BasicLocator(self.shopLocations)
     radius = 1000
     #self.assertRaises(ValueError, locator.Search, -1000, -1000, radius)
     with self.assertRaises(ValueError):
         locator.Search(-1000, -1000, radius)