From 1bd6407ae5a27069b053e49028f2b1eb2c3db706 Mon Sep 17 00:00:00 2001 From: ben Date: Sat, 30 Jul 2016 01:27:53 +0200 Subject: [PATCH] add runtime error for big distances --- pokemongo_bot/constants.py | 1 - pokemongo_bot/step_walker.py | 7 ++++++- tests/test_step_walker.py | 18 +++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) 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 263699095d..fb0bafd8d1 100644 --- a/pokemongo_bot/step_walker.py +++ b/pokemongo_bot/step_walker.py @@ -1,6 +1,6 @@ from math import sqrt -from cell_workers.utils import distance +from cell_workers.utils import distance, float_equal from human_behaviour import random_lat_long_delta, sleep @@ -36,6 +36,11 @@ def __init__(self, bot, speed, dest_lat, dest_lng): self.dLng = (dest_lng - self.initLng) / int(self.steps) self.magnitude = self._pythagorean(self.dLat, self.dLng) + 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(dest_lat, dest_lng, self.dist)) + def step(self): if (self.dLat == 0 and self.dLng == 0) or self.dist < self.speed: self.api.set_position(self.destLat, self.destLng, 0) 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