Skip to content

Commit

Permalink
add runtime error for big distances
Browse files Browse the repository at this point in the history
  • Loading branch information
DayBr3ak committed Jul 29, 2016
1 parent 703513d commit b7084b6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
1 change: 0 additions & 1 deletion pokemongo_bot/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
class Constants(object):
MAX_DISTANCE_FORT_IS_REACHABLE = 40 # meters
NORMALIZED_LAT_LNG_DISTANCE_STEP = 6.3593e-6
8 changes: 7 additions & 1 deletion pokemongo_bot/step_walker.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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):
Expand Down
18 changes: 7 additions & 11 deletions tests/test_step_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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

0 comments on commit b7084b6

Please sign in to comment.