Esempio n. 1
0
def test_merge_identical_nodes():
    mock_conn = DiGraph()
    mock_conn.add_edges_from([('A-1', 'A-5'), ('A-4', 'A-1')])
    mapp = MapGraph()
    # Here we aren't adding the reciprocals, because add_edges_from
    # has been mocked.  And _merge_identical_nodes is designed only to
    # get a node's neighbors (i.e., its successors), assuming that
    # these are the same as its predecessors.
    mapp.add_edges_from([('A-1', 'A-3', {
        'RC': 'S',
        'PDC': 5
    }), ('A-1', 'B-1', {
        'RC': 'I',
        'PDC': 7
    }), ('A-1', 'C-1', {
        'RC': 'L',
        'PDC': 10
    }), ('A-1', 'A-2', {
        'RC': 'I',
        'PDC': 12
    })])
    mapp.cong = mock_conn
    mapp._merge_identical_nodes('A-2', 'A-1')
    nt.assert_equal(mapp.cong.edges(), [('A-2', 'A-5'), ('A-4', 'A-2')])
    nt.assert_equal(mapp.edges(), [('A-2', 'B-1'), ('A-2', 'C-1')])
Esempio n. 2
0
 def setUp(self):
     m = MapGraph()
     m.cong = DiGraph()
     m.add_edges_from([('A00-1', 'B00-1', {
         'RC': 'L',
         'PDC': 0
     }), ('A00-2', 'B00-2', {
         'RC': 'I',
         'PDC': 0
     }), ('A00-3', 'A00-1', {
         'RC': 'L',
         'PDC': 0
     }), ('A00-3', 'A00-2', {
         'RC': 'L',
         'PDC': 0
     }), ('A00-3', 'B00-3', {
         'RC': 'I',
         'PDC': 0
     })])
     m.cong.add_edges_from([('A00-1', 'C00-1', {
         'Connection': 'Present'
     }), ('C00-2', 'A00-2', {
         'Connection': 'Present'
     }), ('A00-3', 'C00-3', {
         'Connection': 'Absent'
     }), ('C00-4', 'A00-3', {
         'Connection': 'Absent'
     })])
     self.m = m
Esempio n. 3
0
def test_keep_one_level():
    # Not mocked: _find_bottom_of_hierarchy,
    # _remove_level_from_hierarchy, _summate_connections.
    hierarchy = {
        'A-J': {
            'A-A': {}
        },
        'A-B': {
            'A-I': {
                'A-F': {
                    'A-K': {},
                    'A-L': {}
                },
                'A-H': {}
            },
            'A-D': {
                'A-E': {}
            }
        }
    }
    mock_conn = DiGraph()
    mock_conn.add_edges_from([('A-D', 'A-Z'), ('A-Y', 'A-F'), ('A-J', 'A-X')])
    mapp = MapGraph()
    mapp.add_nodes_from(
        ['A-A', 'A-B', 'A-D', 'A-E', 'A-F', 'A-H', 'A-I', 'A-J', 'A-K', 'A-L'])
    mapp.cong = mock_conn
    mapp._keep_one_level(hierarchy, 'A')
    nt.assert_equal(mapp.cong.edges(), [('A-J', 'A-X'), ('A-D', 'A-Z'),
                                        ('A-Y', 'A-F')])
    nt.assert_equal(mapp.nodes(), ['A-H', 'A-J', 'A-D', 'A-F'])
Esempio n. 4
0
 def setUp(self):
     m = MapGraph()
     m.cong = DiGraph()
     m.add_edges_from([('A00-1', 'B00-1', {'RC': 'L', 'PDC': 0}),
                       ('A00-2', 'B00-2', {'RC': 'I', 'PDC': 0}),
                       ('A00-3', 'A00-1', {'RC': 'L', 'PDC': 0}),
                       ('A00-3', 'A00-2', {'RC': 'L', 'PDC': 0}),
                       ('A00-3', 'B00-3', {'RC': 'I', 'PDC': 0})])
     m.cong.add_edges_from([('A00-1', 'C00-1', {'Connection': 'Present'}),
                            ('C00-2', 'A00-2', {'Connection': 'Present'}),
                            ('A00-3', 'C00-3', {'Connection': 'Absent'}),
                            ('C00-4', 'A00-3', {'Connection': 'Absent'})])
     self.m = m
Esempio n. 5
0
def test_merge_identical_nodes():
    mock_conn = DiGraph()
    mock_conn.add_edges_from([('A-1', 'A-5'), ('A-4', 'A-1')])
    mapp = MapGraph()
    # Here we aren't adding the reciprocals, because add_edges_from
    # has been mocked.  And _merge_identical_nodes is designed only to
    # get a node's neighbors (i.e., its successors), assuming that
    # these are the same as its predecessors.
    mapp.add_edges_from([('A-1', 'A-3', {'RC': 'S', 'PDC': 5}),
                         ('A-1', 'B-1', {'RC': 'I', 'PDC': 7}),
                         ('A-1', 'C-1', {'RC': 'L', 'PDC': 10}),
                         ('A-1', 'A-2', {'RC': 'I', 'PDC': 12})])
    mapp.cong = mock_conn
    mapp._merge_identical_nodes('A-2', 'A-1')
    nt.assert_equal(mapp.cong.edges(), [('A-2', 'A-5'), ('A-4', 'A-2')])
    nt.assert_equal(mapp.edges(), [('A-2', 'B-1'), ('A-2', 'C-1')])
Esempio n. 6
0
def test_keep_one_level():
    # Not mocked: _find_bottom_of_hierarchy,
    # _remove_level_from_hierarchy, _summate_connections.
    hierarchy = {'A-J': {'A-A': {}},
                 'A-B': {'A-I': {'A-F': {'A-K': {},
                                         'A-L': {}},
                                 'A-H': {}},
                         'A-D': {'A-E': {}}}}
    mock_conn = DiGraph()
    mock_conn.add_edges_from([('A-D', 'A-Z'), ('A-Y', 'A-F'), ('A-J', 'A-X')])
    mapp = MapGraph()
    mapp.add_nodes_from(['A-A', 'A-B', 'A-D', 'A-E', 'A-F', 'A-H', 'A-I',
                         'A-J', 'A-K', 'A-L'])
    mapp.cong = mock_conn
    mapp._keep_one_level(hierarchy, 'A')
    nt.assert_equal(mapp.cong.edges(), [('A-J', 'A-X'), ('A-D', 'A-Z'),
                                        ('A-Y', 'A-F')])
    nt.assert_equal(mapp.nodes(), ['A-H', 'A-J', 'A-D', 'A-F'])