コード例 #1
0
    def test_cut_none(self):
        graph = _graph()

        updated_graph = statistics.cut_edges_by_weight(
            graph,
            7,
            statistics.MakeCuts.LARGER_THAN_EXCLUSIVE,
            prune_isolates=True)
        self.assertEqual(4, len(updated_graph.edges))
        self.assertEqual(8, len(updated_graph.nodes))
コード例 #2
0
    def test_cut_all(self):
        graph = _graph()

        updated_graph = statistics.cut_edges_by_weight(
            graph,
            7,
            statistics.MakeCuts.SMALLER_THAN_INCLUSIVE,
            prune_isolates=True)
        self.assertEqual(0, len(updated_graph.edges))
        self.assertEqual(0, len(updated_graph.nodes))
コード例 #3
0
    def test_make_cuts_smaller_than_inclusive(self):
        graph = _graph()

        updated_graph = statistics.cut_edges_by_weight(
            graph,
            5,
            statistics.MakeCuts.SMALLER_THAN_INCLUSIVE,
            prune_isolates=True)
        self.assertEqual(1, len(updated_graph.edges))
        self.assertEqual(2, len(updated_graph.nodes))
        self.assertEqual(7, updated_graph["nick"]["dwayne"]['weight'])
コード例 #4
0
    def test_make_cuts_larger_than_inclusive(self):
        graph = _graph()

        updated_graph = statistics.cut_edges_by_weight(
            graph,
            5,
            statistics.MakeCuts.LARGER_THAN_INCLUSIVE,
            prune_isolates=True)
        self.assertEqual(2, len(updated_graph.edges))
        self.assertEqual(4, len(updated_graph.nodes))
        self.assertEqual(3, updated_graph[1][2]['weight'])
        self.assertEqual(3, updated_graph[5][4]['weight'])
コード例 #5
0
    def test_make_cuts_smaller_than_exclusive_no_prune_isolates(self):
        graph = _graph()

        updated_graph = statistics.cut_edges_by_weight(
            graph, 5, statistics.MakeCuts.SMALLER_THAN_EXCLUSIVE)
        self.assertEqual(2, len(updated_graph.edges))
        self.assertEqual(8, len(updated_graph.nodes))
        self.assertEqual(5, updated_graph["a"]["b"]['weight'])
        self.assertEqual(7, updated_graph["nick"]["dwayne"]['weight'])
        self.assertIn(1, updated_graph)
        self.assertIn(2, updated_graph)
        self.assertIn(4, updated_graph)
        self.assertIn(5, updated_graph)
コード例 #6
0
 def test_broken_make_cuts(self):
     graph = _graph()
     with self.assertRaises(ValueError):
         statistics.cut_edges_by_weight(graph, 5, None)