add sorted map for byte offset mapping
This commit is contained in:
46
testint2intmaplike.py
Normal file
46
testint2intmaplike.py
Normal 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()
|
||||
Reference in New Issue
Block a user