view tests/test_bisect.py @ 9:638fad06e556

use bisect function; it has been tested faster
author Jeff Hammel <k0scist@gmail.com>
date Sun, 25 Jun 2017 11:37:52 -0700
parents e3d6919130ca
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()