~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__btree_serializer.py

  • Committer: John Arbash Meinel
  • Date: 2010-08-04 01:52:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5390.
  • Revision ID: john@arbash-meinel.com-20100804015214-5dbdub9p0qyc07dp
Add some tests that key lookup works.

Timing shows that looking up all 120 keys takes 205us, using bisect takes 184us.
So better, but not great. I'm a bit surprised it isn't faster, but perhaps
the comparison is a lot less of total time than the conversion to
python objects.

Show diffs side-by-side

added added

removed removed

Lines of Context:
138
138
"""
139
139
 
140
140
_multi_key_content = """type=leaf
141
 
sha1:123456789012345678901234567890abcdefabcd\x00\x001 2 3 4
142
 
sha1:abcd123456789012345678901234567890abcdef\x00\x005678 2345 3456 4567
 
141
sha1:70c881d4a26984ddce795f6f71817c9cf4480e79\x00\x000 0 0 0
 
142
sha1:7e240de74fb1ed08fa08d38063f6a6a91462a815\x00\x001 1 1 1
 
143
sha1:86f7e437faa5a7fce15d1ddcb9eaeaea377667b8\x00\x002 2 2 2
 
144
sha1:da39a3ee5e6b4b0d3255bfef95601890afd80709\x00\x003 3 3 3
 
145
sha1:df51e37c269aa94d38f93e537bf6e2020b21406c\x00\x004 4 4 4
 
146
sha1:e0c9035898dd52fc65c41454cec9c4d2611bfb37\x00\x005 5 5 5
 
147
sha1:e93b4e3c464ffd51732fbd6ded717e9efda28aad\x00\x006 6 6 6
 
148
sha1:f7a9e24777ec23212c54d7a350bc5bea5477fdbb\x00\x007 7 7 7
143
149
"""
144
150
 
145
151
class TestGCCKHSHA1LeafNode(TestBtreeSerializer):
183
189
 
184
190
    def test_many_key_leaf(self):
185
191
        leaf = self.module._parse_into_chk(_multi_key_content, 1, 0)
186
 
        self.assertEqual(2, len(leaf))
187
 
        sha_key1 = ('sha1:' + _hex_form,)
188
 
        sha_key2 = ('sha1:abcd123456789012345678901234567890abcdef',)
189
 
        self.assertEqual([sha_key1, sha_key2], leaf.all_keys())
190
 
        self.assertEqual([(sha_key1, ('1 2 3 4', ())),
191
 
                          (sha_key2, ('5678 2345 3456 4567', ()))
192
 
                         ], leaf.all_items())
193
 
        self.assertTrue(sha_key1 in leaf)
194
 
        self.assertTrue(sha_key2 in leaf)
 
192
        self.assertEqual(8, len(leaf))
 
193
        all_keys = leaf.all_keys()
 
194
        self.assertEqual(8, len(leaf.all_keys()))
 
195
        for idx, key in enumerate(all_keys):
 
196
            self.assertEqual(str(idx), leaf[key][0].split()[0])