def test_neighbors_in(self): net = ECA(30, 3) self.assertEqual(net.neighbors_in(0), set([2, 0, 1])) self.assertEqual(net.neighbors_in(1), set([0, 1, 2])) self.assertEqual(net.neighbors_in(2), set([0, 1, 2])) with self.assertRaises(ValueError): self.assertEqual(net.neighbors_in(3)) net.boundary = (1, 1) self.assertEqual(net.neighbors_in(2), set([1, 2, 3])) with self.assertRaises(ValueError): net.neighbors_in(3) with self.assertRaises(ValueError): net.neighbors_in(5) with self.assertRaises(TypeError): net.neighbors_in('2') with self.assertRaises(ValueError): net.neighbors_in(-1)
def test_to_networkx_metadata(self): net = ECA(30, 3) net.boundary = (1, 0) nx_net = net.network_graph() self.assertEqual(nx_net.graph['code'], 30) self.assertEqual(nx_net.graph['boundary'], (1, 0))
def test_update_values(self): eca = ECA(30, 5) xs = [0, 0, 1, 0, 0] self.assertEqual([0, 1, 0, 1, 0], eca.update(xs, values={2: 0})) self.assertEqual([1, 0, 0, 0, 1], eca.update(xs, values={1: 0, 3: 0})) self.assertEqual([0, 1, 0, 1, 0], eca.update(xs, values={-1: 0})) eca.boundary = (1, 1) xs = [0, 0, 0, 0, 0] self.assertEqual([1, 0, 1, 0, 1], eca.update(xs, values={2: 1}))
def test_update_pin(self): eca = ECA(30, 5) xs = [0, 0, 1, 0, 0] self.assertEqual([0, 0, 1, 1, 0], eca.update(xs, pin=[1])) self.assertEqual([0, 0, 1, 0, 1], eca.update(xs, pin=[1])) self.assertEqual([1, 0, 1, 0, 1], eca.update(xs, pin=[1])) eca.boundary = (1, 1) xs = [0, 0, 0, 0, 0] self.assertEqual([1, 0, 0, 0, 0], eca.update(xs, pin=[-1])) self.assertEqual([1, 1, 0, 0, 0], eca.update(xs, pin=[0, -1]))
def test_neighbors_out(self): net = ECA(30, 3) self.assertEqual(net.neighbors_out(2), set([0, 1, 2])) with self.assertRaises(ValueError): self.assertEqual(net.neighbors_out(3)) net.boundary = (1, 1) self.assertEqual(net.neighbors_out(2), set([1, 2])) with self.assertRaises(ValueError): net.neighbors_out(5) with self.assertRaises(TypeError): net.neighbors_out('2') with self.assertRaises(ValueError): net.neighbors_out(-1)
def test_invalid_boundary(self): eca = ECA(30, 5) eca.boundary = (0, 0) eca.boundary = None with self.assertRaises(ValueError): eca.boundary = (1, 1, 1) with self.assertRaises(ValueError): eca.boundary = (1, 2) with self.assertRaises(TypeError): eca.boundary = 1 with self.assertRaises(TypeError): eca.boundary = [0, 1]