Mercurial > hg > GlobalNeighbors
view 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 |
line wrap: on
line source
#!/usr/bin/env python """ test bisection insert """ import random import unittest from globalneighbors import distance class TestBisectInsert(unittest.TestCase): def test_bisect_insert(self): """ensure our inserted points are in order""" values = [(random.random(), i) for i in range(15000)] for k in (10, 100, 1000, 10000): _distances = [] for value, i in values: distance.insert_distance_bisect(_distances, i, value, k) # since k is < 15000 assert len(_distances) == k ordered = [value[-1] for value in _distances] assert sorted(ordered) == ordered if __name__ == '__main__': unittest.main()