Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision b2144153634a98294a106c6c05738404af5a2f2d authored by Mikhail Kolmogorov on 26 May 2015, 02:06:52 UTC, committed by Mikhail Kolmogorov on 26 May 2015, 02:06:52 UTC
debugging improvements
1 parent 42a3c5d
  • Files
  • Changes
  • 63ff817
  • /
  • lib
  • /
  • networkx
  • /
  • classes
  • /
  • tests
  • /
  • test_digraph_historical.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:b2144153634a98294a106c6c05738404af5a2f2d
directory badge
swh:1:dir:38dd555f410324f15db062b7b02cd1e8a953d9ad
content badge
swh:1:cnt:6bf295c38e76f88d7cb287d3e8aa74e04ff2bf3c

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
test_digraph_historical.py
#!/usr/bin/env python
"""Original NetworkX graph tests"""
from nose.tools import *
import networkx
import networkx as nx

from historical_tests import HistoricalTests

class TestDiGraphHistorical(HistoricalTests):

    def setUp(self):
        HistoricalTests.setUp(self)
        self.G=nx.DiGraph


    def test_in_degree(self):
        G=self.G()
        G.add_nodes_from('GJK')
        G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'), 
                          ('B', 'C'), ('C', 'D')])

        assert_equal(sorted(G.in_degree().values()),[0, 0, 0, 0, 1, 2, 2])
        assert_equal(G.in_degree(),
                     {'A': 0, 'C': 2, 'B': 1, 'D': 2, 'G': 0, 'K': 0, 'J': 0})
        assert_equal(sorted([v for k,v in G.in_degree_iter()]),
                     [0, 0, 0, 0, 1, 2, 2])
        assert_equal(dict(G.in_degree_iter()),
                    {'A': 0, 'C': 2, 'B': 1, 'D': 2, 'G': 0, 'K': 0, 'J': 0})


    def test_out_degree(self):
        G=self.G()
        G.add_nodes_from('GJK')
        G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'), 
                          ('B', 'C'), ('C', 'D')])
        assert_equal(sorted(G.out_degree().values()),[0, 0, 0, 0, 1, 2, 2])
        assert_equal(G.out_degree(),
                     {'A': 2, 'C': 1, 'B': 2, 'D': 0, 'G': 0, 'K': 0, 'J': 0})
        assert_equal(sorted([v for k,v in G.in_degree_iter()]),
                     [0, 0, 0, 0, 1, 2, 2])
        assert_equal(dict(G.out_degree_iter()),
             {'A': 2, 'C': 1, 'B': 2, 'D': 0, 'G': 0, 'K': 0, 'J': 0})


    def test_degree_digraph(self):
        H=nx.DiGraph()
        H.add_edges_from([(1,24),(1,2)])
        assert_equal(sorted(H.in_degree([1,24]).values()),[0, 1])
        assert_equal(sorted(H.out_degree([1,24]).values()),[0, 2])
        assert_equal(sorted(H.degree([1,24]).values()),[1, 2])


    def test_neighbors(self):
        G=self.G()
        G.add_nodes_from('GJK')
        G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'), 
                          ('B', 'C'), ('C', 'D')])

        assert_equal(sorted(G.neighbors('C')),['D'])
        assert_equal(sorted(G['C']),['D'])
        assert_equal(sorted(G.neighbors('A')),['B', 'C'])
        assert_equal(sorted(G.neighbors_iter('A')),['B', 'C'])
        assert_equal(sorted(G.neighbors_iter('C')),['D'])
        assert_equal(sorted(G.neighbors('A')),['B', 'C'])
        assert_raises(nx.NetworkXError,G.neighbors,'j')
        assert_raises(nx.NetworkXError,G.neighbors_iter,'j')

    def test_successors(self):
        G=self.G()
        G.add_nodes_from('GJK')
        G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'), 
                          ('B', 'C'), ('C', 'D')])
        assert_equal(sorted(G.successors('A')),['B', 'C'])
        assert_equal(sorted(G.successors_iter('A')),['B', 'C'])
        assert_equal(sorted(G.successors('G')),[])
        assert_equal(sorted(G.successors('D')),[])
        assert_equal(sorted(G.successors_iter('G')),[])
        assert_raises(nx.NetworkXError,G.successors,'j')
        assert_raises(nx.NetworkXError,G.successors_iter,'j')
        

    def test_predecessors(self):
        G=self.G()
        G.add_nodes_from('GJK')
        G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'), 
                          ('B', 'C'), ('C', 'D')])
        assert_equal(sorted(G.predecessors('C')),['A', 'B'])
        assert_equal(sorted(G.predecessors_iter('C')),['A', 'B'])
        assert_equal(sorted(G.predecessors('G')),[])
        assert_equal(sorted(G.predecessors('A')),[])
        assert_equal(sorted(G.predecessors_iter('G')),[])
        assert_equal(sorted(G.predecessors_iter('A')),[])
        assert_equal(sorted(G.successors_iter('D')),[])

        assert_raises(nx.NetworkXError,G.predecessors,'j')
        assert_raises(nx.NetworkXError,G.predecessors,'j')



    def test_reverse(self):
        G=nx.complete_graph(10)
        H=G.to_directed()
        HR=H.reverse()
        assert_true(nx.is_isomorphic(H,HR))
        assert_equal(sorted(H.edges()),sorted(HR.edges()))

    def test_reverse2(self):
        H=nx.DiGraph()
        foo=[H.add_edge(u,u+1) for u in range(0,5)]
        HR=H.reverse()
        for u in range(0,5):
            assert_true(HR.has_edge(u+1,u))

    def test_reverse3(self):
        H=nx.DiGraph()
        H.add_nodes_from([1,2,3,4])
        HR=H.reverse()
        assert_equal(sorted(HR.nodes()),[1, 2, 3, 4])

The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API