link result view and source view

This commit is contained in:
2021-11-05 19:18:24 +01:00
parent e04c4a2ab7
commit f209156eea
8 changed files with 151 additions and 54 deletions

View File

@@ -2,15 +2,15 @@ import tempfile
import unittest
from os.path import join
from int2intmaplike import Int2IntMapLike
from int2intmap import Int2IntMap
class Int2IntMapLikeTest(unittest.TestCase):
class Int2IntMapLike(unittest.TestCase):
def setUp(self):
self.test_dir = tempfile.TemporaryDirectory()
self.tmpfile = join(self.test_dir.name, "my.log")
self.map = Int2IntMapLike(self.tmpfile)
self.map = Int2IntMap(self.tmpfile)
def tearDown(self):
self.map.close()
@@ -22,23 +22,24 @@ class Int2IntMapLikeTest(unittest.TestCase):
def test_one_line_one_byte(self):
map = self.map
map.add(10, 1, 1) # add only the key 10
map.add(10, 1) # add the key 10
self.assertEqual(None, map.find(9)) # directly before
self.assertEqual(1, map.find(10))
self.assertEqual(None, map.find(11)) # directly after
def test_one_line_two_bytes(self):
map = self.map
map.add(10, 2, 1) # added keys 10 and 11
map.add(10, 1) # added key 10
map.add(11, 2) # added key 11
self.assertEqual(None, map.find(9)) # directly before
self.assertEqual(1, map.find(10))
self.assertEqual(1, map.find(11))
self.assertEqual(2, map.find(11))
self.assertEqual(None, map.find(12)) # directly after
def test_two_lines(self):
map = self.map
map.add(10, 1, 1) # added key 10
map.add(12, 1, 2) # added key 12
map.add(10, 1) # added key 10
map.add(12, 2) # added key 12
self.assertEqual(None, map.find(9)) # directly before
self.assertEqual(1, map.find(10))
self.assertEqual(None, map.find(11)) # between
@@ -54,21 +55,21 @@ class Int2IntMapLikeTest(unittest.TestCase):
# 20,5,2
# 30,5,3
# ...
for i in range(1, 20):
map.add(i * 10, 5, i)
#
# range(1,50) results in 6 blocks a 64 byte
for i in range(1, 50):
# print("add %d"%(i*10))
map.add(i * 10, i)
# print("%d -> blocks: %d" %(i, map.total_blocks()))
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
for j in range(1, i * 10):
if j % 10 == 0:
# values that are in the map
# print("check %d" % (j * 10))
self.assertEqual(j / 10, map.find(j))
else:
# values that are not in the map
self.assertEqual(None, map.find(j))
if __name__ == '__main__':