annotate tests/test_bisect.py @ 13:94af113e498a

we have links
author Jeff Hammel <k0scist@gmail.com>
date Sun, 25 Jun 2017 14:04:49 -0700
parents e3d6919130ca
children 27925261c137
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2 """
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 test bisection insert
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 """
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 import random
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 import unittest
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 from globalneighbors import distance
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 class TestBisectInsert(unittest.TestCase):
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 def test_bisect_insert(self):
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 """ensure our inserted points are in order"""
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 values = [(random.random(), i)
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 for i in range(15000)]
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 for k in (10, 100, 1000, 10000):
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 _distances = []
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 for value, i in values:
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 distance.insert_distance_bisect(_distances,
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 i,
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22 value,
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 k)
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24 # since k is < 15000
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 assert len(_distances) == k
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26 ordered = [value[-1] for value in _distances]
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 assert sorted(ordered) == ordered
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30 if __name__ == '__main__':
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31 unittest.main()