Skip to content

Commit

Permalink
Restored test compatibility with Python 2.6 and added 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
frederickjansen committed Apr 15, 2016
1 parent 32690e1 commit 9c3917b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ python:
- "3.2"
- "3.3"
- "3.4"
- "3.5"
install:
- "make reqs"
script:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Software Development :: Libraries',
'Topic :: Utilities',
),
Expand Down
29 changes: 12 additions & 17 deletions test/test_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,40 +140,35 @@ def test_a_variety_of_precisions(self):
def generator():
while True:
coords = []
for i in range(2, randint(4,10)):
lat, lon = uniform(-180.0,180.0), uniform(-180.0, 180.0)
for i in range(2, randint(4, 10)):
lat, lon = uniform(-180.0, 180.0), uniform(-180.0, 180.0)
xy = (round(lat, 5), round(lon, 5))
coords.append(xy)
yield coords


patience = 3 # seconds.
waypoints, okays = 0, 0

g = generator()
start = time.time()
while time.time() < start + patience:
precision = randint(4, 8)
p = PolylineCodec()
wp = next(g)
waypoints += len(wp)
polyline = p.encode(wp, precision)
wp2 = p.decode(polyline, precision)
polyline = self.codec.encode(wp, precision)
wp2 = self.codec.decode(polyline, precision)
if wp == wp2:
okays += len(wp2)
else:
for idx, _ in enumerate(wp):
dx, dy = abs(wp[idx][0]-wp2[idx][0]), abs(wp[idx][1]-wp2[idx][1])
if dx > 10**-(precision-1) or dy > 10**-(precision-1):
dx, dy = abs(wp[idx][0] - wp2[idx][0]), abs(wp[idx][1] - wp2[idx][1])
if dx > 10 ** -(precision - 1) or dy > 10 ** -(precision - 1):
print("idx={}, dx={}, dy={}".format(idx, dx, dy))
else:
okays += 1

assert okays == waypoints
print("encoded and decoded {:.2f}% correctly for {} waypoints @ {} wp/sec".format(100 * okays / float(waypoints),
waypoints,
round(waypoints/patience,0)))




assert okays == waypoints
print("encoded and decoded {0:.2f}% correctly for {1} waypoints @ {2} wp/sec".format(
100 * okays / float(waypoints),
waypoints,
round(waypoints / patience, 0)))

0 comments on commit 9c3917b

Please sign in to comment.