Ejemplo n.º 1
0
 def setUp(self):
     self.epg = EdgePairGraph(PAIRS)
Ejemplo n.º 2
0
 def setUp(self):
   self.epg = EdgePairGraph(PAIRS)
Ejemplo n.º 3
0
class TestEdgePairGraph(unittest.TestCase):
    def setUp(self):
        self.epg = EdgePairGraph(PAIRS)

    def test_pairs(self):
        self.assert_(self.epg.pairs(copy=False) is PAIRS)
        P = self.epg.pairs(copy=True)
        self.assert_(P is not PAIRS)
        assert_array_equal(P, PAIRS)
        # test the directed case
        P = self.epg.pairs(directed=False)
        assert_array_equal(P, [[0, 1], [0, 2], [1, 1], [1, 2], [3, 3]])

    def test_matrix(self):
        M = self.epg.matrix()
        assert_array_equal(M.toarray(), ADJ)
        M = self.epg.matrix('dense')
        assert_array_equal(M, ADJ)
        M = self.epg.matrix('csr')
        self.assertEqual(M.format, 'csr')
        assert_array_equal(M.toarray(), ADJ)

    def test_self_edges(self):
        self.epg.add_self_edges()
        expected = self.epg.pairs()
        # Ensure that calling it again does the right thing.
        self.epg.add_self_edges()
        assert_array_equal(self.epg.pairs(), expected)

    def test_symmetrize(self):
        # Check that copy=True doesn't change anything
        self.epg.symmetrize(copy=True)
        assert_array_equal(self.epg.matrix('dense'), ADJ)
Ejemplo n.º 4
0
class TestEdgePairGraph(unittest.TestCase):
  def setUp(self):
    self.epg = EdgePairGraph(PAIRS)

  def test_pairs(self):
    self.assert_(self.epg.pairs(copy=False) is PAIRS)
    P = self.epg.pairs(copy=True)
    self.assert_(P is not PAIRS)
    assert_array_equal(P, PAIRS)
    # test the directed case
    P = self.epg.pairs(directed=False)
    assert_array_equal(P, [[0,1],[0,2],[1,1],[1,2],[3,3]])

  def test_matrix(self):
    M = self.epg.matrix()
    assert_array_equal(M.toarray(), ADJ)
    M = self.epg.matrix(dense=True)
    assert_array_equal(M, ADJ)
    M = self.epg.matrix(csr=True)
    self.assertEqual(M.format, 'csr')
    assert_array_equal(M.toarray(), ADJ)

  def test_self_edges(self):
    self.epg.add_self_edges()
    expected = self.epg.pairs()
    # Ensure that calling it again does the right thing.
    self.epg.add_self_edges()
    assert_array_equal(self.epg.pairs(), expected)

  def test_symmetrize(self):
    # Check that copy=True doesn't change anything
    self.epg.symmetrize(copy=True)
    assert_array_equal(self.epg.matrix(dense=True), ADJ)