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 |
||
27 |
def test_matching_lines(self): |
|
28 |
lines = ['a', 'b', 'c', 'b'] |
|
29 |
eq = equivalence_table.EquivalenceTable(lines) |
|
30 |
self.assertEqual(lines, eq._left_lines) |
|
|
0.18.8
by John Arbash Meinel
We don't actually care much about the right-line relationships. We only need to track the left-hand side. |
31 |
self.assertEqual({'a': [0], 'b': [1, 3], 'c': [2]}, |
32 |
eq._matching_lines) |
|
33 |
||
34 |
def assertGetLeftMatches(self, expected_left, eq, right): |
|
|
0.18.2
by John Arbash Meinel
we can now extract what lines in left match the right |
35 |
"""Assert that we find the right matching lines.""" |
|
0.18.8
by John Arbash Meinel
We don't actually care much about the right-line relationships. We only need to track the left-hand side. |
36 |
self.assertEqual(expected_left, eq.get_left_matches(right)) |
|
0.18.2
by John Arbash Meinel
we can now extract what lines in left match the right |
37 |
|
38 |
def test_get_matching(self): |
|
39 |
eq = equivalence_table.EquivalenceTable(['a', 'b', 'c', 'b']) |
|
|
0.18.8
by John Arbash Meinel
We don't actually care much about the right-line relationships. We only need to track the left-hand side. |
40 |
self.assertGetLeftMatches([1, 3], eq, 'b') |
41 |
self.assertGetLeftMatches([2], eq, 'c') |
|
42 |
self.assertGetLeftMatches(None, eq, 'd') |
|
43 |
self.assertGetLeftMatches([2], eq, 'c') |
|
|
0.18.3
by John Arbash Meinel
We can now add more lines to left lines, and continue to track the right info. |
44 |
|
45 |
def test_extend_left_lines(self): |
|
46 |
eq = equivalence_table.EquivalenceTable(['a', 'b', 'c', 'b']) |
|
|
0.18.4
by John Arbash Meinel
Allow ignoring some of the new lines. |
47 |
eq.extend_left_lines(['d', 'e', 'c'], [True, True, True]) |
|
0.18.3
by John Arbash Meinel
We can now add more lines to left lines, and continue to track the right info. |
48 |
self.assertEqual(['a', 'b', 'c', 'b', 'd', 'e', 'c'], |
49 |
eq._left_lines) |
|
|
0.18.8
by John Arbash Meinel
We don't actually care much about the right-line relationships. We only need to track the left-hand side. |
50 |
self.assertEqual({'a': [0], 'b': [1, 3], |
51 |
'c': [2, 6], 'd': [4], |
|
52 |
'e': [5]}, |
|
|
0.18.3
by John Arbash Meinel
We can now add more lines to left lines, and continue to track the right info. |
53 |
eq._matching_lines) |
|
0.18.4
by John Arbash Meinel
Allow ignoring some of the new lines. |
54 |
|
55 |
def test_extend_left_lines_ignored(self): |
|
56 |
eq = equivalence_table.EquivalenceTable(['a', 'b', 'c', 'b']) |
|
57 |
eq.extend_left_lines(['d', 'e', 'c'], [False, False, True]) |
|
58 |
self.assertEqual(['a', 'b', 'c', 'b', 'd', 'e', 'c'], |
|
59 |
eq._left_lines) |
|
|
0.18.8
by John Arbash Meinel
We don't actually care much about the right-line relationships. We only need to track the left-hand side. |
60 |
self.assertEqual({'a': [0], 'b': [1, 3], |
61 |
'c': [2, 6]}, |
|
|
0.18.4
by John Arbash Meinel
Allow ignoring some of the new lines. |
62 |
eq._matching_lines) |
|
0.18.5
by John Arbash Meinel
Add a test that just uses lots of the same lines, |
63 |
|
64 |
def test_abusive(self): |
|
65 |
eq = equivalence_table.EquivalenceTable(['a']*1000) |
|
|
0.18.8
by John Arbash Meinel
We don't actually care much about the right-line relationships. We only need to track the left-hand side. |
66 |
self.assertEqual({'a': range(1000)}, eq._matching_lines) |
67 |
self.assertGetLeftMatches(range(1000), eq, 'a') |