Exemplo n.º 1
0
    def test_directed_graphs(self):
        # Directed butterfly (interpret the undirected edges as directed
        edges = pysaucy2.examples.butterfly().to_edge_lists()
        dir_butterfly = pysaucy2.Graph(edges, directed=True)

        result = pysaucy2.run_saucy(dir_butterfly)

        self.assertTupleEqual(result, (1.0, 0, 1, 1, 0, 0, 0))

        g1 = pysaucy2.Graph([[1], []])
        res1 = g1.run_saucy()
        g2 = pysaucy2.Graph([[1], [0]], directed=True)
        res2 = g2.run_saucy()
        self.assertTupleEqual(res1, res2)
Exemplo n.º 2
0
    def test_wrong_parameters(self):
        with self.assertRaises(TypeError) as e:
            pysaucy2.Graph([1])

        self.assertIn('object of type \'int\' has no len()', str(e.exception))

        with self.assertRaises(TypeError) as e:
            pysaucy2.Graph([["1", 2, 3], [""]])

        with self.assertRaises(ValueError) as e:
            pysaucy2.Graph([[1, 2, 3], []])

        with self.assertRaises(OverflowError) as e:
            pysaucy2.Graph([[2**31], []])

        with self.assertRaises(ValueError):
            pysaucy2.Graph([[2 ** 31 - 1], []])
Exemplo n.º 3
0
    def test_loops(self):
        # Loop, no automorphisms
        g1 = pysaucy2.Graph([[0, 1], []])
        result = pysaucy2.run_saucy(g1)
        self.assertEqual(result, (1.0, 0, 1, 1, 0, 0, 0))
        self.assertEqual(g1.orbits, [0, 1])

        # No loop, automorphisms
        g2 = pysaucy2.Graph([[1], []])
        result = pysaucy2.run_saucy(g2)
        self.assertEqual(result, (2.0, 0, 2, 3, 0, 1, 2))
        self.assertEqual(g2.orbits, [0, 0])

        # Loops, automorphisms
        g3 = pysaucy2.Graph([[0, 1], [1]])
        result = pysaucy2.run_saucy(g3)
        self.assertEqual(result, (2.0, 0, 2, 3, 0, 1, 2))
        self.assertEqual(g3.orbits, [0, 0])
Exemplo n.º 4
0
    def test_large_graph(self):
        edge_lists = None

        with open(os.path.abspath(os.path.join('pysaucy2', 'tests', 'inf-belgium_osm_saucy.graph'))) as graph_file:
            n, m, _ = graph_file.readline().split()
            n, m = int(n), int(m)
            edge_lists = [[] for _ in range(n)]
            for line in graph_file:
                i, j = map(int, line.split())
                if i > j:
                    edge_lists[j].append(i)
                else:
                    edge_lists[i].append(j)

        g = pysaucy2.Graph(edge_lists)

        ts = datetime.datetime.now()
        res = g.run_saucy()
        run_time = datetime.datetime.now() - ts

        self.assertTupleEqual(res, (6.965030094591524, 1812, 5987, 12091, 0, 5986, 26536))
        self.assertLessEqual(run_time.total_seconds(), 5, msg='This test may have failed because your running it '
                                                              'on a slow machine')
Exemplo n.º 5
0
    def test_null_graph(self):
        with self.assertRaises(ValueError) as e:
            pysaucy2.Graph([])

        self.assertIn('The graph without nodes is not allowed', str(e.exception))
Exemplo n.º 6
0
 def test_empty_k10(self):
     empty = pysaucy2.Graph([[]]*10)
     result = pysaucy2.run_saucy(empty)
     self.assertTupleEqual(tuple(list(result)[:7]), (3.6287999999999996, 6, 10, 35, 0, 9, 18))