def test_find_campers_around_match(self): camper1 = {"id": 1, "latitude": 1.0, "longitude": 1.0} camper2 = {"id": 2, "latitude": -1.0, "longitude": -1.0} data = {"campers": [camper1, camper2]} DataStoreAccess.populate_campers(self.ds, data) results = DataStoreAccess.find_campers_around(self.ds, Point(1.0, 1.0)) self.assertListEqual([Camper(**camper1)], results) results = DataStoreAccess.find_campers_around(self.ds, Point(1.09, 1.09)) self.assertListEqual([Camper(**camper1)], results) results = DataStoreAccess.find_campers_around(self.ds, Point(0.91, 0.91)) self.assertListEqual([Camper(**camper1)], results) results = DataStoreAccess.find_campers_around(self.ds, Point(1.09, 0.91)) self.assertListEqual([Camper(**camper1)], results) results = DataStoreAccess.find_campers_around(self.ds, Point(0.91, 1.09)) self.assertListEqual([Camper(**camper1)], results) results = DataStoreAccess.find_campers_around(self.ds, Point(-1.0, -1.0)) self.assertListEqual([Camper(**camper2)], results) results = DataStoreAccess.find_campers_around(self.ds, Point(-1.09, -0.91)) self.assertListEqual([Camper(**camper2)], results)
def test_find_campers_around_nomatch(self): camper1 = {"id": 1, "latitude": 1.0, "longitude": 1.0} camper2 = {"id": 1, "latitude": -1.0, "longitude": -1.0} data = {"campers": [camper1, camper2]} DataStoreAccess.populate_campers(self.ds, data) results = DataStoreAccess.find_campers_around(self.ds, Point(0.0, 0.0)) self.assertListEqual(results, []) results = DataStoreAccess.find_campers_around(self.ds, Point(1.0, 0.0)) self.assertListEqual(results, []) results = DataStoreAccess.find_campers_around(self.ds, Point(0.0, 1.0)) self.assertListEqual(results, [])
def test_find_campers_around_nomatch(self): data = {"campers": [self.camper1, self.camper2]} DataStoreAccess.populate_campers(self.ds, data) nomatch_points = [ Point(0.0, 0.0), Point(1.0, 0.0), Point(0.0, 1.0), ] expected_res = [] for p in nomatch_points: results = DataStoreAccess.find_campers_around(self.ds, p) self.assertListEqual(results, expected_res, f"failed for {p}")
def test_find_campers_around_match(self): data = {"campers": [self.camper1, self.camper2]} DataStoreAccess.populate_campers(self.ds, data) pos_points = [ Point(1.0, 1.0), Point(1.1, 1.1), Point(0.9, 0.9), Point(1.1, 0.9), Point(0.9, 1.1), ] expected_res = [Camper(**self.camper1)] for p in pos_points: results = DataStoreAccess.find_campers_around(self.ds, p) self.assertListEqual(results, expected_res, f"failed for {p}") neg_points = [Point(-1.0, -1.0), Point(-1.1, -0.9)] expected_res = [Camper(**self.camper2)] for p in neg_points: results = DataStoreAccess.find_campers_around(self.ds, p) self.assertListEqual(results, expected_res, f"failed for {p}")
def test_find_campers_between_dates(self): data = { "campers": [self.camper1, self.camper4, self.camper3, self.camper2] } DataStoreAccess.populate_campers(self.ds, data) sd = datetime.fromisoformat("2020-01-01") ed = datetime.fromisoformat("2020-01-08") results = DataStoreAccess.find_campers_between_dates( self.ds, Point(1.0, 1.0), sd, sd) self.assertListEqual(results, [ Camper(**self.camper1), Camper(**self.camper3), Camper(**self.camper4), ], "test sort one day") results = DataStoreAccess.find_campers_between_dates( self.ds, Point(1.0, 1.0), sd, ed) self.assertListEqual(results, [ Camper(**self.camper3), Camper(**self.camper1), Camper(**self.camper4), ], "test sort days >= 7")
def test_populate_campers(self): data = {"campers": [self.camper1]} DataStoreAccess.populate_campers(self.ds, data) self.assertDictEqual(self.ds.store, {1: Camper(**self.camper1)})
def test_populate_campers(self): camper1 = {"id": 1, "latitude": 1.0, "longitude": 1.0} data = {"campers": [camper1]} DataStoreAccess.populate_campers(self.ds, data) self.assertDictEqual(self.ds.store, {1: Camper(**camper1)})