def test_types(self):
     ls_hood = Neighbourhood(self.ls)
     nd_hood = Neighbourhood(self.ndarray)
     self.assertEqual(type(ls_hood), type(nd_hood))
     self.assertTrue(
         np.array_equal(ls_hood.neighbourhood, nd_hood.neighbourhood))
     self.assertEqual(type(ls_hood.neighbourhood),
                      type(nd_hood.neighbourhood))
 def test(self):
     n = Neighbourhood(arr, dims=2)
     self.assertIsInstance(n, Neighbourhood)
     if type(testagainst) == tuple:
         self.assertTrue(n.neighbourhood.shape == testagainst)
     else:
         self.assertTrue(
             np.array_equal(n.neighbourhood, testagainst))
示例#3
0
    def set_neighbourhood(self, ca_config):
        """Sets self.neighbourhood with a Neighbourhood object
        from ca_config

        Args:
            ca_config (CAConfig): the config object with the
                neighbourhood array stored"""
        self.neighbourhood = ca_config.neighbourhood()
        if not (Neighbourhood is (self.neighbourhood.__class__)):
            self.neighbourhood = Neighbourhood(self.neighbourhood,
                                               dims=ca_config.dimensions)
示例#4
0
 def neighbourhood(self):
     if self.nhood_arr is None:
         self.nhood_arr = [0, 1, 0]
     return Neighbourhood(self.nhood_arr, dims=self.dimensions)
 def test_nd(self):
     hood = Neighbourhood(self.ndarray)
     self.assertIsInstance(hood, Neighbourhood)
 def test_empty2d(self):
     empty = np.array([[]])
     control = np.zeros((3, 3))
     control[1, 1] = 1
     n = Neighbourhood(empty)
     self.assertTrue(np.array_equal(n.neighbourhood, control))
 def test_ls(self):
     ls_hood = Neighbourhood(self.ls)
     self.assertIsInstance(ls_hood, Neighbourhood)
 def test(self):
     l = lambda: Neighbourhood(nhood=arr, dims=dims)
     self.assertRaises(ValueError, l)
 def test(self):
     n = Neighbourhood(arr, dims=dims)
     self.assertIsInstance(n, Neighbourhood)
 def test_empty1D(self):
     empty = np.array([])
     control = np.array([0, 1, 0])
     n = Neighbourhood(empty, dims=1)
     self.assertTrue(np.array_equal(n.neighbourhood, control))