Show More
@@ -1,77 +1,85 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2017 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | from rhodecode.lib import graphmod |
|
22 | 22 | |
|
23 | 23 | |
|
24 | 24 | # pylint: disable=protected-access |
|
25 | 25 | |
|
26 | 26 | |
|
27 | 27 | def test_get_edge_color_multiple_parents(): |
|
28 | 28 | node_color = 1 |
|
29 | 29 | parent_color = 2 |
|
30 | 30 | assert graphmod._get_edge_color( |
|
31 | 31 | 'parent', 2, node_color, {'parent': parent_color}) == parent_color |
|
32 | 32 | |
|
33 | 33 | |
|
34 | 34 | def test_get_edge_color_multiple_unknown_parent(): |
|
35 | 35 | node_color = 1 |
|
36 | 36 | assert graphmod._get_edge_color('parent', 2, node_color, {}) == node_color |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | def test_get_edge_color_single_parent(): |
|
40 | 40 | node_color = 1 |
|
41 | 41 | assert graphmod._get_edge_color('parent', 1, node_color, {}) == node_color |
|
42 | 42 | |
|
43 | 43 | |
|
44 | 44 | def test_colored_linear(): |
|
45 | dag = [('node3', ['node2']), ('node2', ['node1']), ('node1', [])] | |
|
45 | dag = [ | |
|
46 | ('hash', 'node3', ['node2'], 'master'), | |
|
47 | ('hash', 'node2', ['node1'], 'master'), | |
|
48 | ('hash', 'node1', [], 'master') | |
|
49 | ] | |
|
46 | 50 | expected_result = [ |
|
47 | ((0, 1), [(0, 0, 1)]), | |
|
48 | ((0, 1), [(0, 0, 1)]), | |
|
49 | ((0, 1), []), | |
|
51 | ('hash', (0, 1), [(0, 0, 1)], 'master'), | |
|
52 | ('hash', (0, 1), [(0, 0, 1)], 'master'), | |
|
53 | ('hash', (0, 1), [], 'master'), | |
|
50 | 54 | ] |
|
51 | 55 | assert list(graphmod._colored(dag)) == expected_result |
|
52 | 56 | |
|
53 | 57 | |
|
54 | 58 | def test_colored_diverging_branch(): |
|
55 | dag = [('node3', ['node1']), ('node2', ['node1']), ('node1', [])] | |
|
59 | dag = [ | |
|
60 | ('hash', 'node3', ['node1'], 'stable'), | |
|
61 | ('hash', 'node2', ['node1'], 'stable'), | |
|
62 | ('hash', 'node1', [], 'stable') | |
|
63 | ] | |
|
56 | 64 | expected_result = [ |
|
57 | ((0, 1), [(0, 0, 1)]), | |
|
58 | ((1, 2), [(0, 0, 1), (1, 0, 2)]), | |
|
59 | ((0, 1), []), | |
|
65 | ('hash', (0, 1), [(0, 0, 1)], 'stable'), | |
|
66 | ('hash', (1, 2), [(0, 0, 1), (1, 0, 2)], 'stable'), | |
|
67 | ('hash', (0, 1), [], 'stable'), | |
|
60 | 68 | ] |
|
61 | 69 | assert list(graphmod._colored(dag)) == expected_result |
|
62 | 70 | |
|
63 | 71 | |
|
64 | 72 | def test_colored_merged_branch(): |
|
65 | 73 | dag = [ |
|
66 | ('node4', ['node2', 'node3']), | |
|
67 | ('node3', ['node1']), | |
|
68 | ('node2', ['node1']), | |
|
69 | ('node1', []), | |
|
74 | ('hash', 'node4', ['node2', 'node3'], 'stable'), | |
|
75 | ('hash', 'node3', ['node1'], 'stable'), | |
|
76 | ('hash', 'node2', ['node1'], 'stable'), | |
|
77 | ('hash', 'node1', [], 'stable'), | |
|
70 | 78 | ] |
|
71 | 79 | expected_result = [ |
|
72 | ((0, 1), [(0, 0, 1), (0, 1, 2)]), | |
|
73 | ((1, 2), [(0, 0, 1), (1, 1, 2)]), | |
|
74 | ((0, 1), [(0, 0, 1), (1, 0, 2)]), | |
|
75 | ((0, 2), []), | |
|
80 | ('hash', (0, 1), [(0, 0, 1), (0, 1, 2)], 'stable'), | |
|
81 | ('hash', (1, 2), [(0, 0, 1), (1, 1, 2)], 'stable'), | |
|
82 | ('hash', (0, 1), [(0, 0, 1), (1, 0, 2)], 'stable'), | |
|
83 | ('hash', (0, 2), [], 'stable'), | |
|
76 | 84 | ] |
|
77 | 85 | assert list(graphmod._colored(dag)) == expected_result |
General Comments 0
You need to be logged in to leave comments.
Login now