diff --git a/pokemongo_bot/constants.py b/pokemongo_bot/constants.py index 43352ae576..70912e8409 100644 --- a/pokemongo_bot/constants.py +++ b/pokemongo_bot/constants.py @@ -1,3 +1,2 @@ class Constants(object): MAX_DISTANCE_FORT_IS_REACHABLE = 40 # meters - NORMALIZED_LAT_LNG_DISTANCE_STEP = 6.3593e-6 diff --git a/pokemongo_bot/step_walker.py b/pokemongo_bot/step_walker.py index b39cb4ce9d..ca7d50eec7 100644 --- a/pokemongo_bot/step_walker.py +++ b/pokemongo_bot/step_walker.py @@ -1,7 +1,7 @@ from math import sqrt from pokemongo_bot import logger -from cell_workers.utils import distance, i2f +from cell_workers.utils import distance, i2f, float_equal from human_behaviour import random_lat_long_delta, sleep import sys @@ -36,6 +36,12 @@ def __init__(self, bot, speed, destLat, destLng): else: self.dLat = (destLat - self.initLat) / int(self.steps) self.dLng = (destLng - self.initLng) / int(self.steps) + + if float_equal(self.dLat, 0) or float_equal(self.dLng, 0): + # the distance is too big + raise RuntimeError("lat: {}, lng: {} aren't valid (too far) - dist = {}" + .format(destLat, destLng, self.dist)) + self.magnitude = self._pythagorean(self.dLat, self.dLng) def step(self): diff --git a/tests/test_step_walker.py b/tests/test_step_walker.py index dace9b1808..9d3dc52f67 100644 --- a/tests/test_step_walker.py +++ b/tests/test_step_walker.py @@ -5,6 +5,8 @@ from pokemongo_bot.constants import Constants from pokemongo_bot.cell_workers.utils import float_equal +NORMALIZED_LAT_LNG_DISTANCE_STEP = 6.3593e-6 + class TestStepWalker(object): def setup(self): self.patcherSleep = patch('pokemongo_bot.step_walker.sleep') @@ -33,8 +35,8 @@ def test_normalized_distance(self): flag = sw.step() ok_(flag != True) - ok_(float_equal(self.lat, Constants.NORMALIZED_LAT_LNG_DISTANCE_STEP)) - ok_(float_equal(self.lng, Constants.NORMALIZED_LAT_LNG_DISTANCE_STEP)) + ok_(float_equal(self.lat, NORMALIZED_LAT_LNG_DISTANCE_STEP)) + ok_(float_equal(self.lng, NORMALIZED_LAT_LNG_DISTANCE_STEP)) def test_normalized_distance_times_2(self): sw = StepWalker(self.bot, 2, 0.1, 0.1) @@ -44,8 +46,8 @@ def test_normalized_distance_times_2(self): flag = sw.step() ok_(flag != True) - ok_(float_equal(self.lat, Constants.NORMALIZED_LAT_LNG_DISTANCE_STEP * 2)) - ok_(float_equal(self.lng, Constants.NORMALIZED_LAT_LNG_DISTANCE_STEP * 2)) + ok_(float_equal(self.lat, NORMALIZED_LAT_LNG_DISTANCE_STEP * 2)) + ok_(float_equal(self.lng, NORMALIZED_LAT_LNG_DISTANCE_STEP * 2)) def test_small_distance_same_spot(self): sw = StepWalker(self.bot, 1, 0, 0) @@ -61,12 +63,6 @@ def test_small_distance_small_step(self): ok_(sw.dLat == 0) ok_(sw.dLng == 0) - + @raises(RuntimeError) def test_big_distances(self): - ### BUG - sw = StepWalker(self.bot, 1, 10, 10) - ok_(sw.dLat == 0) - ok_(sw.dLng == 0) - - ## this test should pass ? if the distance is too big, the bot doesn't move