comparison tests/test_bisect.py @ 8:e3d6919130ca

insert via BST
author Jeff Hammel <k0scist@gmail.com>
date Sun, 25 Jun 2017 11:21:28 -0700
parents
children 27925261c137
comparison
equal deleted inserted replaced
7:254195d0bac2 8:e3d6919130ca
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
28
29
30 if __name__ == '__main__':
31 unittest.main()