/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.18.1 by John Arbash Meinel
Start working on an EquivalenceTable construct.
1
# Copyright (C) 2008 Canonical Limited.
2
#
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.
6
#
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.
11
#
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
15
#
16
17
from bzrlib import tests
18
19
from bzrlib.plugins.groupcompress import equivalence_table
20
21
22
class TestEquivalenceTable(tests.TestCase):
23
24
    def test_create(self):
25
        eq = equivalence_table.EquivalenceTable(['a', 'b'])
26
        eq.set_right_lines(['b', 'd'])
27
28
    def test_matching_lines(self):
29
        lines = ['a', 'b', 'c', 'b']
30
        eq = equivalence_table.EquivalenceTable(lines)
31
        self.assertEqual(lines, eq._left_lines)
32
        self.assertEqual({'a': ([0], []), 'b': ([1, 3], []), 'c': ([2], [])},
33
                         eq._matching_lines)
34
35
    def test_add_right_lines(self):
36
        left_lines = ['a', 'b', 'c', 'b']
37
        eq = equivalence_table.EquivalenceTable(left_lines)
38
        self.assertEqual({'a': ([0], []), 'b': ([1, 3], []), 'c': ([2], [])},
39
                         eq._matching_lines)
40
        right_lines = ['b', 'c', 'd', 'c']
41
        eq.set_right_lines(right_lines)
42
        self.assertEqual({'a': ([0], []), 'b': ([1, 3], [0]),
43
                          'c': ([2], [1, 3]), 'd': ([], [2])},
44
                         eq._matching_lines)
45
46
    def test_add_new_right_lines(self):
47
        eq = equivalence_table.EquivalenceTable(['a', 'b', 'c', 'b'])
48
        eq.set_right_lines(['b', 'c', 'd', 'c'])
49
        eq.set_right_lines(['a', 'f', 'c', 'f'])
50
        self.assertEqual({'a': ([0], [0]), 'b': ([1, 3], []),
51
                          'c': ([2], [2]), 'f': ([], [1, 3])},
52
                         eq._matching_lines)
0.18.2 by John Arbash Meinel
we can now extract what lines in left match the right
53
54
    def assertGetLeftMatches(self, expected_left, eq, right_idx):
55
        """Assert that we find the right matching lines."""
56
        self.assertEqual(expected_left, eq.get_left_matches(right_idx))
57
58
    def test_get_matching(self):
59
        eq = equivalence_table.EquivalenceTable(['a', 'b', 'c', 'b'])
60
        eq.set_right_lines(['b', 'c', 'd', 'c'])
61
62
        self.assertGetLeftMatches([1, 3], eq, 0)
63
        self.assertGetLeftMatches([2], eq, 1)
64
        self.assertGetLeftMatches([], eq, 2)
65
        self.assertGetLeftMatches([2], eq, 3)
0.18.3 by John Arbash Meinel
We can now add more lines to left lines, and continue to track the right info.
66
67
    def test_extend_left_lines(self):
68
        eq = equivalence_table.EquivalenceTable(['a', 'b', 'c', 'b'])
69
        eq.set_right_lines(['b', 'c', 'd', 'c'])
70
        eq.extend_left_lines(['d', 'e', 'c'])
71
        self.assertEqual(['a', 'b', 'c', 'b', 'd', 'e', 'c'],
72
                         eq._left_lines)
73
        self.assertEqual({'a': ([0], []), 'b': ([1, 3], [0]),
74
                          'c': ([2, 6], [1, 3]), 'd': ([4], [2]),
75
                          'e': ([5], [])},
76
                         eq._matching_lines)