old_contents: # Copyright (c) 2013 Spotify AB
  #
  # Licensed under the Apache License, Version 2.0 (the "License"); you may not
  # use this file except in compliance with the License. You may obtain a copy of
  # the License at
  #
  # http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  # License for the specific language governing permissions and limitations under
  # the License.
  
  import numpy
  import random
  from common import TestCase
  from annoy import AnnoyIndex
  
  
  class HolesTest(TestCase):
      def test_holes(self):
          # See https://github.com/spotify/annoy/issues/223
          f = 10
          index = AnnoyIndex(f)
          index.add_item(1000, numpy.random.normal(size=(f,)))
          index.build(10)
          js = index.get_nns_by_vector(numpy.random.normal(size=(f,)), 100)
          self.assertEquals(js, [1000])
  
      def test_holes_more(self):
          f = 10
          index = AnnoyIndex(f)
          valid_indices = random.sample(range(2000), 1000) # leave holes
          for i in valid_indices:
              v = numpy.random.normal(size=(f,))
              index.add_item(i, v)
          index.build(10)
          for i in valid_indices:
              js = index.get_nns_by_item(i, 10000)
              for j in js:
                  self.assertTrue(j in valid_indices)
          for i in range(1000):
              v = numpy.random.normal(size=(f,))
              js = index.get_nns_by_vector(v, 10000)
              for j in js:
                  self.assertTrue(j in valid_indices)
  
      def test_holes_even_more(self):
          # See https://github.com/spotify/annoy/issues/295
          annoy = AnnoyIndex(100)
          base_i, n = 100000, 10
          for i in range(n):
              annoy.add_item(base_i + i, [random.gauss(0, 1) for z in range(100)])
          annoy.build(100)
          res = annoy.get_nns_by_item(base_i, n)
          self.assertEquals(set(res), set([base_i + i for i in range(n)]))
  
new_contents: # Copyright (c) 2013 Spotify AB
  #
  # Licensed under the Apache License, Version 2.0 (the "License"); you may not
  # use this file except in compliance with the License. You may obtain a copy of
  # the License at
  #
  # http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  # License for the specific language governing permissions and limitations under
  # the License.
  
  import numpy
  import random
  from common import TestCase
  from annoy import AnnoyIndex
  
  
  class HolesTest(TestCase):
      def test_root_one_child(self):
          # See https://github.com/spotify/annoy/issues/223
          f = 10
          index = AnnoyIndex(f)
          index.add_item(1000, numpy.random.normal(size=(f,)))
          index.build(10)
          js = index.get_nns_by_vector(numpy.random.normal(size=(f,)), 100)
          self.assertEquals(js, [1000])
  
      def test_many_holes(self):
          f = 10
          index = AnnoyIndex(f)
          valid_indices = random.sample(range(2000), 1000) # leave holes
          for i in valid_indices:
              v = numpy.random.normal(size=(f,))
              index.add_item(i, v)
          index.build(10)
          for i in valid_indices:
              js = index.get_nns_by_item(i, 10000)
              for j in js:
                  self.assertTrue(j in valid_indices)
          for i in range(1000):
              v = numpy.random.normal(size=(f,))
              js = index.get_nns_by_vector(v, 10000)
              for j in js:
                  self.assertTrue(j in valid_indices)
  
      def test_holes_many_children(self):
          # See https://github.com/spotify/annoy/issues/295
          f, base_i, n = 100, 100000, 10
          annoy = AnnoyIndex(f)
          for i in range(n):
              annoy.add_item(base_i + i, numpy.random.normal(size=(f,)))
          annoy.build(100)
          res = annoy.get_nns_by_item(base_i, n)
          self.assertEquals(set(res), set([base_i + i for i in range(n)]))
  
      def test_root_two_children(self):
          # See https://github.com/spotify/annoy/issues/223
          f = 10
          index = AnnoyIndex(f)
          index.add_item(1000, numpy.random.normal(size=(f,)))
          index.add_item(1001, numpy.random.normal(size=(f,)))
          index.build(10)
          js = index.get_nns_by_vector(numpy.random.normal(size=(f,)), 100)
          self.assertEquals(set(js), set([1000, 1001]))
  
subject: add another test since i'm paranoid