Ejemplo n.º 1
0
    def test_modify_adjacency(self):
        # Test normal usage
        network = Constructor()
        network.set_grid(5, 5, 100)
        network.modify_adjacency(10, 0.1, 0.1)
        adjacency = network.get_adjacency()
        modified_adjacency = network.get_modified_adjacency()
        self.assertEqual(len(modified_adjacency), 25)
        for i in range(25):
            for j in range(25):
                if adjacency[i][j] == 0:
                    self.assertTrue(modified_adjacency[i][j] == 0)
                else:
                    self.assertFalse(modified_adjacency[i][j] == 0)

        with self.assertRaises(ValueError):  # width=0
            network.modify_adjacency(0, 0.1, 0.1)
Ejemplo n.º 2
0
 def test_change_beta(self):
     # Test normal usage
     network = Constructor()
     network.set_grid(5, 5, 100)
     network.modify_adjacency(10, 0.1, 0.8)
     network.change_beta(0, 1, 0.5)
     adjacency = network.get_adjacency()
     modified_adjacency = network.get_modified_adjacency()
     self.assertEqual(modified_adjacency[0][1]["beta"], 0.5)
     self.assertEqual(modified_adjacency[1][0]["beta"], 0.5)
     for i in range(1, 25):
         for j in range(1, 25):
             if adjacency[i][j] == 1:
                 self.assertEqual(modified_adjacency[i][j]["beta"], 0.8)
     # Test wrong usage
     with self.assertRaises(ValueError):  # alpha>1
         network.change_beta(0, 1, 2)
     with self.assertRaises(ValueError):  # alpha<0
         network.change_beta(0, 1, -1)
     with self.assertRaises(ValueError):  # nodes not neighbours
         network.change_beta(0, 2, 0.5)
     with self.assertRaises(ValueError):  # nodes out of range
         network.change_beta(0, 25, 0.5)
Ejemplo n.º 3
0
 def test_change_width(self):
     # Test normal usage
     network = Constructor()
     network.set_grid(5, 5, 100)
     network.modify_adjacency(20, 0.1, 0.1)
     network.change_width(0, 1, 50)
     adjacency = network.get_adjacency()
     modified_adjacency = network.get_modified_adjacency()
     self.assertEqual(modified_adjacency[0][1]["width"], 50)
     self.assertEqual(modified_adjacency[1][0]["width"], 50)
     for i in range(1, 25):
         for j in range(1, 25):
             if adjacency[i][j] == 1:
                 self.assertEqual(modified_adjacency[i][j]["width"], 20)
     # Test wrong usage
     with self.assertRaises(ValueError):  # width=0
         network.change_width(0, 1, 0)
     with self.assertRaises(ValueError):  # width<0
         network.change_width(0, 1, -10)
     with self.assertRaises(ValueError):  # nodes not neighbours
         network.change_width(0, 2, 50)
     with self.assertRaises(ValueError):  #nodes out of range
         network.change_width(0, 25, 20)