add sorted map for byte offset mapping

This commit is contained in:
2021-11-03 20:07:59 +01:00
parent b8581449ad
commit cbc167ada8
2 changed files with 116 additions and 0 deletions

46
testint2intmaplike.py Normal file
View File

@@ -0,0 +1,46 @@
import tempfile
import unittest
from os.path import join
from int2intmaplike import Int2IntMapLike
class Int2IntMapLikeTest(unittest.TestCase):
def setUp(self):
self.test_dir = tempfile.TemporaryDirectory()
self.tmpfile = join(self.test_dir.name, "my.log")
self.map = Int2IntMapLike(self.tmpfile)
def tearDown(self):
self.map.close()
self.test_dir.cleanup()
def test_fill_map(self):
map = self.map
map.blocksize = 64
# fill map with
# 10,5,1
# 20,5,2
# 30,5,3
# ...
for i in range(1, 20):
map.add(i * 10, 5, i)
self.assertEqual(2, map.find(20))
self.assertEqual(7, map.find(71))
self.assertEqual(13, map.find(134))
self.assertEqual(19, map.find(194))
# values that are not in the map
self.assertEqual(None, map.find(0))
self.assertEqual(None, map.find(9))
self.assertEqual(None, map.find(15))
self.assertEqual(None, map.find(16))
self.assertEqual(None, map.find(107)) # a value in the second block
self.assertEqual(None, map.find(188)) # a value in the third block
if __name__ == '__main__':
unittest.main()