view tests/test_bisect.py @ 25:991bce6b6881 default tip

[knn] placeholder for planning session
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Sep 2017 14:35:50 -0700
parents 27925261c137
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()