示例#1
0
    def test_incorrect_probability(self):
        """ Tests the setter for probabilities outside [0, 1] """

        top = topology.custom()
        top.push_back()
        top.push_back()

        # Add edges with valid probability
        top.add_edge(0, 1, 0.1)
        top.add_edge(1, 0, 0.1)
        top.set_weight(0.1)
        top.set_weight(0, 0.1)
        top.set_weight(0, 1, 0.1)

        self.assertRaises(ValueError, top.set_weight, -0.1)
        self.assertRaises(ValueError, top.set_weight, 0, -0.1)
        self.assertRaises(ValueError, top.set_weight, 0, 1, -0.1)

        self.assertRaises(ValueError, top.set_weight, 1.1)
        self.assertRaises(ValueError, top.set_weight, 0, 1.1)
        self.assertRaises(ValueError, top.set_weight, 0, 1, 1.1)

        # Add new vertex and try to add_edge with incorrect probability
        top.push_back()
        self.assertRaises(ValueError, top.add_edge, 1, 2, -0.1)
        self.assertRaises(ValueError, top.add_edge, 2, 1, 1.1)
示例#2
0
    def test_mixed_migr_representation(self):
        """ Testing the mixing of different edge weight setters """

        t = topology.custom()
        t.push_back()
        t.push_back()
        t.push_back()
        t.push_back()
        t.add_edge(0, 1)
        t.add_edge(1, 0)
        t.add_edge(1, 2)
        self.assertEqual(t.get_weight(0, 1), 1.0)
        self.assertEqual(t.get_weight(1, 0), 1.0)
        self.assertEqual(t.get_weight(1, 2), 1.0)
        t.set_weight(1, 0.5)  # Set weight for each out-going edge of vertex 1
        self.assertEqual(t.get_weight(0, 1), 1.0)
        self.assertEqual(t.get_weight(1, 0), 0.5)
        self.assertEqual(t.get_weight(1, 2), 0.5)
        t.add_edge(1, 3)  # Weight of a new out-going edge of vertex 1 should still be 1.0 by default
        self.assertEqual(t.get_weight(1, 0), 0.5)
        self.assertEqual(t.get_weight(1, 2), 0.5)
        self.assertEqual(t.get_weight(1, 3), 1.0)

        t.set_weight(0.3)  # Set the weight to all edges
        self.assertEqual(t.get_weight(0, 1), 0.3)
        self.assertEqual(t.get_weight(1, 0), 0.3)
        self.assertEqual(t.get_weight(1, 2), 0.3)
        self.assertEqual(t.get_weight(1, 3), 0.3)
        t.add_edge(2, 3)  # Weight of a new edge should still be 1.0 by default

        self.assertEqual(t.get_weight(0, 1), 0.3)
        self.assertEqual(t.get_weight(1, 0), 0.3)
        self.assertEqual(t.get_weight(1, 2), 0.3)
        self.assertEqual(t.get_weight(1, 3), 0.3)
        self.assertEqual(t.get_weight(2, 3), 1.0)
示例#3
0
    def test_incorrect_probability(self):
        """ Tests the setter for probabilities outside [0, 1] """

        top = topology.custom()
        top.push_back()
        top.push_back()

        # Add edges with valid probability
        top.add_edge(0, 1, 0.1)
        top.add_edge(1, 0, 0.1)
        top.set_weight(0.1)
        top.set_weight(0, 0.1)
        top.set_weight(0, 1, 0.1)

        self.assertRaises(ValueError, top.set_weight, -0.1)
        self.assertRaises(ValueError, top.set_weight, 0, -0.1)
        self.assertRaises(ValueError, top.set_weight, 0, 1, -0.1)

        self.assertRaises(ValueError, top.set_weight, 1.1)
        self.assertRaises(ValueError, top.set_weight, 0, 1.1)
        self.assertRaises(ValueError, top.set_weight, 0, 1, 1.1)

        # Add new vertex and try to add_edge with incorrect probability
        top.push_back()
        self.assertRaises(ValueError, top.add_edge, 1, 2, -0.1)
        self.assertRaises(ValueError, top.add_edge, 2, 1, 1.1)
示例#4
0
    def test_overloaded_add_edge(self):
        """ Tests the add_edge(n, m, weight) setter """

        t = topology.custom()
        t.push_back()
        t.push_back()
        t.push_back()
        t.add_edge(0, 1, 0.1)
        t.add_edge(2, 0)  # 1.0 by default
        t.add_edge(0, 2, 0.3)
        self.assertEqual(t.get_weight(0, 1), 0.1)
        self.assertEqual(t.get_weight(2, 0), 1.0)
        self.assertEqual(t.get_weight(0, 2), 0.3)
示例#5
0
    def test_overloaded_add_edge(self):
        """ Tests the add_edge(n, m, weight) setter """

        t = topology.custom()
        t.push_back()
        t.push_back()
        t.push_back()
        t.add_edge(0, 1, 0.1)
        t.add_edge(2, 0)  # 1.0 by default
        t.add_edge(0, 2, 0.3)
        self.assertEqual(t.get_weight(0, 1), 0.1)
        self.assertEqual(t.get_weight(2, 0), 1.0)
        self.assertEqual(t.get_weight(0, 2), 0.3)
示例#6
0
 def test_basic_probs(self):
     """ Tests the basic getter/setter for custom migration probability """
     t = topology.custom()
     t.push_back()
     t.push_back()
     t.push_back()
     t.add_edge(0, 1)
     t.add_edge(2, 0)
     t.add_edge(0, 2)
     t.set_weight(2, 0, 0.1)
     t.set_weight(0, 2, 0.2)
     self.assertEqual(t.get_weight(0, 1), 1.0)  # This one should be set by default
     self.assertEqual(t.get_weight(2, 0), 0.1)
     self.assertEqual(t.get_weight(0, 2), 0.2)
示例#7
0
 def test_basic_probs(self):
     """ Tests the basic getter/setter for custom migration probability """
     t = topology.custom()
     t.push_back()
     t.push_back()
     t.push_back()
     t.add_edge(0, 1)
     t.add_edge(2, 0)
     t.add_edge(0, 2)
     t.set_weight(2, 0, 0.1)
     t.set_weight(0, 2, 0.2)
     self.assertEqual(t.get_weight(0, 1),
                      1.0)  # This one should be set by default
     self.assertEqual(t.get_weight(2, 0), 0.1)
     self.assertEqual(t.get_weight(0, 2), 0.2)
示例#8
0
    def test_average_path_length(self):
        """ Testing the average path length algorithm """

        top = topology.ring(2)
        self.assertEqual(top.get_average_shortest_path_length(), 1.0)
        top = topology.ring(3)
        self.assertEqual(top.get_average_shortest_path_length(), 1.0)
        top = topology.ring(5)
        self.assertEqual(top.get_average_shortest_path_length(), 1.5)
        top = topology.ring(9)
        self.assertEqual(top.get_average_shortest_path_length(), 2.5)
        top = topology.custom()
        top.push_back()
        top.push_back()
        top.push_back()
        top.push_back()
        top.add_edge(0, 1)
        top.add_edge(1, 2)
        top.add_edge(2, 3)
        top.add_edge(3, 0)
        top.add_edge(0, 2)
        self.assertEqual(top.get_average_shortest_path_length(), 1.75)
示例#9
0
    def test_average_path_length(self):
        """ Testing the average path length algorithm """

        top = topology.ring(2)
        self.assertEqual(top.get_average_shortest_path_length(), 1.0)
        top = topology.ring(3)
        self.assertEqual(top.get_average_shortest_path_length(), 1.0)
        top = topology.ring(5)
        self.assertEqual(top.get_average_shortest_path_length(), 1.5)
        top = topology.ring(9)
        self.assertEqual(top.get_average_shortest_path_length(), 2.5)
        top = topology.custom()
        top.push_back()
        top.push_back()
        top.push_back()
        top.push_back()
        top.add_edge(0, 1)
        top.add_edge(1, 2)
        top.add_edge(2, 3)
        top.add_edge(3, 0)
        top.add_edge(0, 2)
        self.assertEqual(top.get_average_shortest_path_length(), 1.75)
示例#10
0
    def test_mixed_migr_representation(self):
        """ Testing the mixing of different edge weight setters """

        t = topology.custom()
        t.push_back()
        t.push_back()
        t.push_back()
        t.push_back()
        t.add_edge(0, 1)
        t.add_edge(1, 0)
        t.add_edge(1, 2)
        self.assertEqual(t.get_weight(0, 1), 1.0)
        self.assertEqual(t.get_weight(1, 0), 1.0)
        self.assertEqual(t.get_weight(1, 2), 1.0)
        t.set_weight(1, 0.5)  # Set weight for each out-going edge of vertex 1
        self.assertEqual(t.get_weight(0, 1), 1.0)
        self.assertEqual(t.get_weight(1, 0), 0.5)
        self.assertEqual(t.get_weight(1, 2), 0.5)
        t.add_edge(
            1, 3
        )  # Weight of a new out-going edge of vertex 1 should still be 1.0 by default
        self.assertEqual(t.get_weight(1, 0), 0.5)
        self.assertEqual(t.get_weight(1, 2), 0.5)
        self.assertEqual(t.get_weight(1, 3), 1.0)

        t.set_weight(0.3)  # Set the weight to all edges
        self.assertEqual(t.get_weight(0, 1), 0.3)
        self.assertEqual(t.get_weight(1, 0), 0.3)
        self.assertEqual(t.get_weight(1, 2), 0.3)
        self.assertEqual(t.get_weight(1, 3), 0.3)
        t.add_edge(2, 3)  # Weight of a new edge should still be 1.0 by default

        self.assertEqual(t.get_weight(0, 1), 0.3)
        self.assertEqual(t.get_weight(1, 0), 0.3)
        self.assertEqual(t.get_weight(1, 2), 0.3)
        self.assertEqual(t.get_weight(1, 3), 0.3)
        self.assertEqual(t.get_weight(2, 3), 1.0)