view tests/test_bisect.py @ 14:27925261c137

fix broken tests including an aggregious case where we add ourselves as a neighbor to ourself
author Jeff Hammel <k0scist@gmail.com>
date Sun, 25 Jun 2017 14:29:18 -0700
parents e3d6919130ca
children
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
            keys = [value[0] for value in _distances]
            assert len(set(keys)) == len(_distances)


if __name__ == '__main__':
    unittest.main()