Exemplo n.º 1
0
 def test_update_index_no_index(self):
     # Test calling update index with no existing index.  Should result the
     # same as calling build_index with no index.
     i = LinearHashIndex()
     # noinspection PyTypeChecker
     i.update_index([[0, 1, 0], [1, 0, 0], [0, 1, 1], [0, 0, 1]])
     self.assertEqual(i.index, {1, 2, 3, 4})
     self.assertIsNone(i.cache_element)
Exemplo n.º 2
0
 def test_update_index_add_hashes(self):
     i = LinearHashIndex()
     # Build index with some initial hashes
     # noinspection PyTypeChecker
     i.build_index([[0, 0], [0, 1]])
     self.assertSetEqual(i.index, {0, 1})
     # Update index with new stuff
     # noinspection PyTypeChecker
     i.update_index([[1, 0], [1, 1]])
     self.assertSetEqual(i.index, {0, 1, 2, 3})
Exemplo n.º 3
0
 def test_update_index_no_index(self):
     # Test calling update index with no existing index.  Should result the
     # same as calling build_index with no index.
     i = LinearHashIndex()
     # noinspection PyTypeChecker
     i.update_index([[0, 1, 0],
                     [1, 0, 0],
                     [0, 1, 1],
                     [0, 0, 1]])
     self.assertEqual(i.index, {1, 2, 3, 4})
     self.assertIsNone(i.cache_element)
Exemplo n.º 4
0
 def test_update_index_add_hashes(self):
     i = LinearHashIndex()
     # Build index with some initial hashes
     # noinspection PyTypeChecker
     i.build_index([[0, 0],
                    [0, 1]])
     self.assertSetEqual(i.index, {0, 1})
     # Update index with new stuff
     # noinspection PyTypeChecker
     i.update_index([[1, 0],
                     [1, 1]])
     self.assertSetEqual(i.index, {0, 1, 2, 3})
Exemplo n.º 5
0
    def test_save_cache_update_index(self):
        cache_element = DataMemoryElement()
        self.assertTrue(cache_element.is_empty())

        i = LinearHashIndex(cache_element)
        # noinspection PyTypeChecker
        i.build_index([[0, 1, 0],   # 2
                       [1, 0, 0]])  # 4
        # noinspection PyTypeChecker
        i.update_index([[0, 1, 1],   # 3
                        [0, 0, 1]])  # 1
        self.assertFalse(cache_element.is_empty())
        # Check byte content
        expected_cache = {1, 2, 3, 4}
        actual_cache = set(numpy.load(BytesIO(cache_element.get_bytes())))
        self.assertSetEqual(expected_cache, actual_cache)
Exemplo n.º 6
0
    def test_save_cache_update_index(self):
        cache_element = DataMemoryElement()
        self.assertTrue(cache_element.is_empty())

        i = LinearHashIndex(cache_element)
        # noinspection PyTypeChecker
        i.build_index([
            [0, 1, 0],  # 2
            [1, 0, 0]
        ])  # 4
        # noinspection PyTypeChecker
        i.update_index([
            [0, 1, 1],  # 3
            [0, 0, 1]
        ])  # 1
        self.assertFalse(cache_element.is_empty())
        # Check byte content
        expected_cache = {1, 2, 3, 4}
        actual_cache = set(numpy.load(BytesIO(cache_element.get_bytes())))
        self.assertSetEqual(expected_cache, actual_cache)