comparison 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
comparison
equal deleted inserted replaced
6:316e1d54ffd4 7:254195d0bac2
4 test distance calculation 4 test distance calculation
5 """ 5 """
6 6
7 import math 7 import math
8 import os 8 import os
9 import random
9 import unittest 10 import unittest
10 from globalneighbors import distance 11 from globalneighbors import distance
11 from globalneighbors.constants import Rearth 12 from globalneighbors.constants import Rearth
12 from globalneighbors.locations import locations 13 from globalneighbors.locations import locations
13 from globalneighbors.read import read_cities 14 from globalneighbors.read import read_cities
125 # assert distances increase 126 # assert distances increase
126 for value in neighbors.values(): 127 for value in neighbors.values():
127 distances = [i[-1] for i in value] 128 distances = [i[-1] for i in value]
128 assert distances == sorted(distances) 129 assert distances == sorted(distances)
129 130
131 def test_insert_distances(self):
132 """test insert distances algorithm"""
133
134 values = [(i, random.random())
135 for i in range(1500)]
136 for k in (10, 100, 1000):
137 _distances = []
138 for i, value in values:
139 distance.insert_distance(_distances,
140 i,
141 value,
142 k)
143 # since k is < 1500
144 assert len(_distances) == k
145 ordered = [value[-1] for value in _distances]
146 assert sorted(ordered) == ordered
147
130 148
131 if __name__ == '__main__': 149 if __name__ == '__main__':
132 unittest.main() 150 unittest.main()