~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tests/test_groupcompress.py

new encoder, allows non monotonically increasing sequence matches for moar compression.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
        expected_lines = [
65
65
            'label: label\n',
66
66
            'sha1: %s\n' % sha1,
67
 
            '0,0,3\n',
 
67
            'i,3\n',
68
68
            'strange\n',
69
69
            'common\n',
70
70
            '\n', # the last \n in a text is removed, which allows safe
77
77
        compressor = groupcompress.GroupCompressor(True)
78
78
        sha1_1, _ = compressor.compress(('label',),
79
79
            ['strange\n', 'common\n'], None)
 
80
        expected_lines = list(compressor.lines)
80
81
        sha1_2, end_point = compressor.compress(('newlabel',),
81
82
            ['common\n', 'different\n'], None)
82
83
        self.assertEqual(sha_strings(['common\n', 'different\n']), sha1_2)
83
 
        expected_lines = [
84
 
            'label: label\n',
85
 
            'sha1: %s\n' % sha1_1,
86
 
            '0,0,3\n',
87
 
            'strange\n',
88
 
            'common\n',
89
 
            '\n',
 
84
        expected_lines.extend([
90
85
            'label: newlabel\n',
91
86
            'sha1: %s\n' % sha1_2,
92
 
            # Delete what we don't want. Perhaps we want an implicit
93
 
            # delete all to keep from bloating with useless delete
94
 
            # instructions.
95
 
            '0,4,0\n',
96
 
            # add the new lines
97
 
            '5,5,1\n',
 
87
            # copy the line common
 
88
            'c,4,1\n',
 
89
            # add the line different
 
90
            'i,1\n',
98
91
            'different\n',
99
 
            ]
 
92
            # copy the line \n. Note that when we filter on encoding-overhead
 
93
            # this will become a fresh insert instead
 
94
            'c,5,1\n',
 
95
            ])
100
96
        self.assertEqual(expected_lines, compressor.lines)
101
97
        self.assertEqual(sum(map(len, expected_lines)), end_point)
102
98
 
108
104
            ['strange\n', 'common\n'], None)
109
105
        sha1_2, _ = compressor.compress(('newlabel',),
110
106
            ['common\n', 'different\n', 'moredifferent\n'], None)
 
107
        expected_lines = list(compressor.lines)
111
108
        sha1_3, end_point = compressor.compress(('label3',),
112
109
            ['new\n', 'common\n', 'different\n', 'moredifferent\n'], None)
113
110
        self.assertEqual(
114
111
            sha_strings(['new\n', 'common\n', 'different\n', 'moredifferent\n']),
115
112
            sha1_3)
116
 
        expected_lines = [
117
 
            'label: label\n',
118
 
            'sha1: %s\n' % sha1_1,
119
 
            '0,0,3\n',
120
 
            'strange\n',
121
 
            'common\n',
122
 
            '\n',
123
 
            'label: newlabel\n',
124
 
            'sha1: %s\n' % sha1_2,
125
 
            # Delete what we don't want. Perhaps we want an implicit
126
 
            # delete all to keep from bloating with useless delete
127
 
            # instructions.
128
 
            '0,4,0\n',
129
 
            # add the new lines
130
 
            '5,5,2\n',
131
 
            'different\n',
132
 
            'moredifferent\n',
 
113
        expected_lines.extend([
133
114
            'label: label3\n',
134
115
            'sha1: %s\n' % sha1_3,
135
 
            # Delete what we don't want. Perhaps we want an implicit
136
 
            # delete all to keep from bloating with useless delete
137
 
            # instructions.
138
 
            # replace 'strange' with 'new'
139
 
            '0,4,1\n',
 
116
            # insert new
 
117
            'i,1\n',
140
118
            'new\n',
141
 
            # delete from after common up to differnet
142
 
            '5,10,0\n',
143
 
            # add new \n
144
 
            '12,12,1\n',
145
 
            '\n',
146
 
            ]
 
119
            # copy the line common
 
120
            'c,4,1\n',
 
121
            # copy the lines different, moredifferent
 
122
            'c,10,2\n',
 
123
            # copy the line \n. Note that when we filter on encoding-overhead
 
124
            # this will become a fresh insert instead
 
125
            'c,5,1\n',
 
126
            ])
147
127
        self.assertEqualDiff(''.join(expected_lines), ''.join(compressor.lines))
148
128
        self.assertEqual(sum(map(len, expected_lines)), end_point)
149
129