diff tests/test_distance.py @ 7:254195d0bac2

partial implementation of autocomplete using jqueryui; easyautocomplete.com may be more what we want
author Jeff Hammel <k0scist@gmail.com>
date Sun, 25 Jun 2017 09:13:48 -0700
parents 49aae0c0293b
children 27925261c137
line wrap: on
line diff
--- a/tests/test_distance.py	Sat Jun 24 15:47:59 2017 -0700
+++ b/tests/test_distance.py	Sun Jun 25 09:13:48 2017 -0700
@@ -6,6 +6,7 @@
 
 import math
 import os
+import random
 import unittest
 from globalneighbors import distance
 from globalneighbors.constants import Rearth
@@ -127,6 +128,23 @@
                 distances = [i[-1] for i in value]
                 assert distances == sorted(distances)
 
+    def test_insert_distances(self):
+        """test insert distances algorithm"""
+
+        values = [(i, random.random())
+                  for i in range(1500)]
+        for k in (10, 100, 1000):
+            _distances = []
+            for i, value in values:
+                distance.insert_distance(_distances,
+                                         i,
+                                         value,
+                                         k)
+            # since k is < 1500
+            assert len(_distances) == k
+            ordered = [value[-1] for value in _distances]
+            assert sorted(ordered) == ordered
+
 
 if __name__ == '__main__':
     unittest.main()