~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_index.py

Explicitly mark the number of keys elements in use in GraphIndex files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
        builder = GraphIndexBuilder()
28
28
        stream = builder.finish()
29
29
        contents = stream.read()
30
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=0\n\n", contents)
 
30
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=0\nkey_elements=1\n\n", contents)
31
31
 
32
32
    def test_build_index_one_reference_list_empty(self):
33
33
        builder = GraphIndexBuilder(reference_lists=1)
34
34
        stream = builder.finish()
35
35
        contents = stream.read()
36
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\n\n", contents)
 
36
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\nkey_elements=1\n\n", contents)
37
37
 
38
38
    def test_build_index_two_reference_list_empty(self):
39
39
        builder = GraphIndexBuilder(reference_lists=2)
40
40
        stream = builder.finish()
41
41
        contents = stream.read()
42
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=2\n\n", contents)
 
42
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=2\nkey_elements=1\n\n", contents)
43
43
 
44
44
    def test_build_index_one_node_no_refs(self):
45
45
        builder = GraphIndexBuilder()
46
46
        builder.add_node(('akey', ), 'data')
47
47
        stream = builder.finish()
48
48
        contents = stream.read()
49
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=0\n"
 
49
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=0\nkey_elements=1\n"
50
50
            "akey\x00\x00\x00data\n\n", contents)
51
51
 
52
52
    def test_build_index_one_node_no_refs_accepts_empty_reflist(self):
54
54
        builder.add_node(('akey', ), 'data', ())
55
55
        stream = builder.finish()
56
56
        contents = stream.read()
57
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=0\n"
 
57
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=0\nkey_elements=1\n"
58
58
            "akey\x00\x00\x00data\n\n", contents)
59
59
 
60
60
    def test_add_node_empty_value(self):
62
62
        builder.add_node(('akey', ), '')
63
63
        stream = builder.finish()
64
64
        contents = stream.read()
65
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=0\n"
 
65
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=0\nkey_elements=1\n"
66
66
            "akey\x00\x00\x00\n\n", contents)
67
67
 
68
68
    def test_build_index_two_nodes_sorted(self):
76
76
        builder.add_node(('2001', ), 'data')
77
77
        stream = builder.finish()
78
78
        contents = stream.read()
79
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=0\n"
 
79
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=0\nkey_elements=1\n"
80
80
            "2000\x00\x00\x00data\n"
81
81
            "2001\x00\x00\x00data\n"
82
82
            "2002\x00\x00\x00data\n"
87
87
        builder.add_node(('key', ), 'data', ([], ))
88
88
        stream = builder.finish()
89
89
        contents = stream.read()
90
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\n"
 
90
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\nkey_elements=1\n"
91
91
            "key\x00\x00\x00data\n"
92
92
            "\n", contents)
93
93
 
96
96
        builder.add_node(('key', ), 'data', ([], []))
97
97
        stream = builder.finish()
98
98
        contents = stream.read()
99
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=2\n"
 
99
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=2\nkey_elements=1\n"
100
100
            "key\x00\x00\t\x00data\n"
101
101
            "\n", contents)
102
102
 
106
106
        builder.add_node(('key', ), 'data', ([('reference', )], ))
107
107
        stream = builder.finish()
108
108
        contents = stream.read()
109
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\n"
110
 
            "key\x00\x0051\x00data\n"
 
109
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\nkey_elements=1\n"
 
110
            "key\x00\x0066\x00data\n"
111
111
            "reference\x00\x00\x00data\n"
112
112
            "\n", contents)
113
113
 
118
118
        builder.add_node(('key', ), 'data', ([('reference', ), ('reference2', )], ))
119
119
        stream = builder.finish()
120
120
        contents = stream.read()
121
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\n"
122
 
            "key\x00\x0054\r71\x00data\n"
 
121
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\nkey_elements=1\n"
 
122
            "key\x00\x00071\r088\x00data\n"
123
123
            "reference\x00\x00\x00data\n"
124
124
            "reference2\x00\x00\x00data\n"
125
125
            "\n", contents)
130
130
        builder.add_node(('rey', ), 'data', ([('keference', )], [('keference', )]))
131
131
        stream = builder.finish()
132
132
        contents = stream.read()
133
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=2\n"
 
133
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=2\nkey_elements=1\n"
134
134
            "keference\x00\x00\t\x00data\n"
135
 
            "rey\x00\x0038\t38\x00data\n"
 
135
            "rey\x00\x0053\t53\x00data\n"
136
136
            "\n", contents)
137
137
 
138
138
    def test_add_node_referencing_missing_key_makes_absent(self):
140
140
        builder.add_node(('rey', ), 'data', ([('beference', ), ('aeference2', )], ))
141
141
        stream = builder.finish()
142
142
        contents = stream.read()
143
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\n"
 
143
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\nkey_elements=1\n"
144
144
            "aeference2\x00a\x00\x00\n"
145
145
            "beference\x00a\x00\x00\n"
146
 
            "rey\x00\x0053\r38\x00data\n"
 
146
            "rey\x00\x0068\r53\x00data\n"
147
147
            "\n", contents)
148
148
 
149
149
    def test_node_references_three_digits(self):
153
153
        builder.add_node(('2-key', ), '', (references, ))
154
154
        stream = builder.finish()
155
155
        contents = stream.read()
156
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\n"
 
156
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\nkey_elements=1\n"
157
157
            "0\x00a\x00\x00\n"
158
158
            "1\x00a\x00\x00\n"
159
159
            "2\x00a\x00\x00\n"
160
 
            "2-key\x00\x00130\r124\r118\r112\r106\r100\r050\r044\r038\x00\n"
 
160
            "2-key\x00\x00145\r139\r133\r127\r121\r115\r065\r059\r053\x00\n"
161
161
            "3\x00a\x00\x00\n"
162
162
            "4\x00a\x00\x00\n"
163
163
            "5\x00a\x00\x00\n"
173
173
        builder.add_node(('parent', ), '', ([('aail', ), ('zther', )], []))
174
174
        stream = builder.finish()
175
175
        contents = stream.read()
176
 
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=2\n"
 
176
        self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=2\nkey_elements=1\n"
177
177
            "aail\x00a\x00\x00\n"
178
 
            "parent\x00\x0038\r63\t\x00\n"
 
178
            "parent\x00\x0053\r78\t\x00\n"
179
179
            "zther\x00a\x00\x00\n"
180
180
            "\n", contents)
181
181