Пример #1
0
    def test_a_variety_of_precisions(self):
        """uses a generator to create a variety of lat-lon's across the global
            and tests a range of precision settings from 4 to 8"""
        def generator():
            while True:
                trajectory = []
                curr_t = 1582482600
                for i in range(2, randint(4, 10)):
                    lat, lon, curr_t = (
                        uniform(-180.0, 180.0),
                        uniform(-180.0, 180.0),
                        curr_t + uniform(2, 60),
                    )
                    trajectory.append((lat, lon, curr_t))
                yield trajectory

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

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

        self.assertEqual(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),
            ))
Пример #2
0
 def test_encode_and_decode_with_precision_6(self):
     data = self.decoded
     e = trajectory.encode(data, 6)
     d = trajectory.decode(e, 6)
     self.assertEqual(d, data)
Пример #3
0
 def test_encode_with_precision_6(self):
     e = trajectory.encode(self.decoded, 6)
     self.assertEqual(e, self.encoded_precision_6)
Пример #4
0
 def test_encode_and_decode(self):
     data = self.decoded
     e = trajectory.encode(data)
     d = trajectory.decode(e)
     self.assertEqual(d, data)
Пример #5
0
 def test_encode(self):
     e = trajectory.encode(self.decoded)
     self.assertEqual(e, self.encoded)
Пример #6
0
 def test_encode_rounding(self):
     e = trajectory.encode([(0, 0.000006, 1582482601),
                            (0, 0.000002, 1582482601)])
     self.assertEqual(e, "?A_ynpijgz~G?@?")