示例#1
0
 def test_update_index_no_index(self) -> None:
     # 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)
示例#2
0
 def test_update_index_add_hashes(self) -> None:
     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})
示例#3
0
    def test_save_cache_update_index(self) -> None:
        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)