Mercurial > hg > GlobalNeighbors
annotate tests/test_bisect.py @ 20:2fef925fbf37
display country + population in autocomplete drop down
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 25 Jun 2017 16:12:08 -0700 |
parents | 27925261c137 |
children |
rev | line source |
---|---|
8 | 1 #!/usr/bin/env python |
2 """ | |
3 test bisection insert | |
4 """ | |
5 | |
6 import random | |
7 import unittest | |
8 from globalneighbors import distance | |
9 | |
10 class TestBisectInsert(unittest.TestCase): | |
11 | |
12 def test_bisect_insert(self): | |
13 """ensure our inserted points are in order""" | |
14 | |
15 values = [(random.random(), i) | |
16 for i in range(15000)] | |
17 for k in (10, 100, 1000, 10000): | |
18 _distances = [] | |
19 for value, i in values: | |
20 distance.insert_distance_bisect(_distances, | |
21 i, | |
22 value, | |
23 k) | |
24 # since k is < 15000 | |
25 assert len(_distances) == k | |
26 ordered = [value[-1] for value in _distances] | |
27 assert sorted(ordered) == ordered | |
14
27925261c137
fix broken tests including an aggregious case where we add ourselves as a neighbor to ourself
Jeff Hammel <k0scist@gmail.com>
parents:
8
diff
changeset
|
28 keys = [value[0] for value in _distances] |
27925261c137
fix broken tests including an aggregious case where we add ourselves as a neighbor to ourself
Jeff Hammel <k0scist@gmail.com>
parents:
8
diff
changeset
|
29 assert len(set(keys)) == len(_distances) |
8 | 30 |
31 | |
32 if __name__ == '__main__': | |
33 unittest.main() |