annotate 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
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
14
27925261c137 fix broken tests including an aggregious case where we add ourselves as a neighbor to ourself
Jeff Hammel <k0scist@gmail.com>
parents: 8
diff changeset
28 keys = [value[0] for value in _distances]
27925261c137 fix broken tests including an aggregious case where we add ourselves as a neighbor to ourself
Jeff Hammel <k0scist@gmail.com>
parents: 8
diff changeset
29 assert len(set(keys)) == len(_distances)
8
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
32 if __name__ == '__main__':
e3d6919130ca insert via BST
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
33 unittest.main()