1
# Copyright (C) 2008 Canonical Limited.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License version 2 as published
5
# by the Free Software Foundation.
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
# GNU General Public License for more details.
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
from bzrlib import tests
19
from bzrlib.plugins.groupcompress import equivalence_table
20
from bzrlib.plugins.groupcompress.tests.test__groupcompress_c import (
25
class TestEquivalenceTable(tests.TestCase):
27
eq_class = equivalence_table.EquivalenceTable
29
def test_create(self):
30
eq = self.eq_class(['a', 'b'])
32
def test_matching_lines(self):
33
lines = ['a', 'b', 'c', 'b']
34
eq = self.eq_class(lines)
35
self.assertEqual(lines, eq.lines)
36
self.assertEqual({'a': [0], 'b': [1, 3], 'c': [2]},
37
eq._get_matching_lines())
39
def test_set_right_lines(self):
40
eq = self.eq_class(['a', 'b', 'c', 'b'])
41
eq.set_right_lines(['f', 'b', 'b'])
42
self.assertEqual(None, eq.get_idx_matches(0))
43
self.assertEqual([1, 3], eq.get_idx_matches(1))
44
self.assertEqual([1, 3], eq.get_idx_matches(2))
46
def assertGetLeftMatches(self, expected_left, eq, right):
47
"""Assert that we find the right matching lines."""
48
self.assertEqual(expected_left, eq.get_matches(right))
50
def test_get_matching(self):
51
eq = self.eq_class(['a', 'b', 'c', 'b'])
52
self.assertGetLeftMatches([1, 3], eq, 'b')
53
self.assertGetLeftMatches([2], eq, 'c')
54
self.assertGetLeftMatches(None, eq, 'd')
55
self.assertGetLeftMatches([2], eq, 'c')
57
def test_extend_lines(self):
58
eq = self.eq_class(['a', 'b', 'c', 'b'])
59
eq.extend_lines(['d', 'e', 'c'], [True, True, True])
60
self.assertEqual(['a', 'b', 'c', 'b', 'd', 'e', 'c'],
62
self.assertEqual({'a': [0], 'b': [1, 3],
63
'c': [2, 6], 'd': [4],
65
eq._get_matching_lines())
67
def test_extend_lines_ignored(self):
68
eq = self.eq_class(['a', 'b', 'c', 'b'])
69
eq.extend_lines(['d', 'e', 'c'], [False, False, True])
70
self.assertEqual(['a', 'b', 'c', 'b', 'd', 'e', 'c'],
72
self.assertEqual({'a': [0], 'b': [1, 3],
73
'c': [2, 6], 'd': None, 'e': None},
74
eq._get_matching_lines())
76
def test_abusive(self):
77
eq = self.eq_class(['a']*1000)
78
self.assertEqual({'a': range(1000)}, eq._get_matching_lines())
79
self.assertGetLeftMatches(range(1000), eq, 'a')
82
class TestCompiledEquivalenceTable(TestEquivalenceTable):
84
_tests_need_features = [CompiledGroupCompress]
87
super(TestCompiledEquivalenceTable, self).setUp()
88
from bzrlib.plugins.groupcompress import _groupcompress_c
89
self.eq_class = _groupcompress_c.EquivalenceTable