Example #1
0
    def test_cut_none(self):
        graph = _get_toy_graph()

        updated_graph = graph_cuts.cut_edges_by_weight(
            graph, 7, graph_cuts.LARGER_THAN_EXCLUSIVE, prune_isolates=True)
        self.assertEqual(4, len(updated_graph.edges))
        self.assertEqual(8, len(updated_graph.nodes))
Example #2
0
    def test_cut_all(self):
        graph = _get_toy_graph()

        updated_graph = graph_cuts.cut_edges_by_weight(
            graph, 7, graph_cuts.SMALLER_THAN_INCLUSIVE, prune_isolates=True)
        self.assertEqual(0, len(updated_graph.edges))
        self.assertEqual(0, len(updated_graph.nodes))
Example #3
0
    def test_make_cuts_smaller_than_inclusive(self):
        graph = _get_toy_graph()

        updated_graph = graph_cuts.cut_edges_by_weight(
            graph, 5, graph_cuts.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"])
Example #4
0
    def test_make_cuts_larger_than_inclusive(self):
        graph = _get_toy_graph()

        updated_graph = graph_cuts.cut_edges_by_weight(
            graph, 5, graph_cuts.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"])
Example #5
0
    def test_make_cuts_smaller_than_exclusive_no_prune_isolates(self):
        graph = _get_toy_graph()

        updated_graph = graph_cuts.cut_edges_by_weight(
            graph, 5, graph_cuts.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)
Example #6
0
 def test_broken_make_cuts(self):
     graph = _get_toy_graph()
     with self.assertRaises(ValueError):
         graph_cuts.cut_edges_by_weight(graph, 5, None)