def test_update_index_error(self): eca = ECA(30, 2) with self.assertRaises(IndexError): eca.update([0, 0], index=2) with self.assertRaises(IndexError): eca.update([0, 0], index=-1)
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_update_values_pin_clash(self): eca = ECA(30, 5) with self.assertRaises(ValueError): eca.update([0, 0, 0, 0, 0], pin=[0], values={0: 1}) with self.assertRaises(ValueError): eca.update([0, 0, 0, 0, 0], pin=[1], values={1: 0}) with self.assertRaises(ValueError): eca.update([0, 0, 0, 0, 0], pin=[1], values={0: 0, 1: 0}) with self.assertRaises(ValueError): eca.update([0, 0, 0, 0, 0], pin=[1, 0], values={0: 0})
def test_reproduce_open_ecas(self): """ Ensure that RewiredECAs can reproduce open ECAs """ reca = RewiredECA(30, boundary=(1, 0), size=7) eca = ECA(30, size=7, boundary=(1, 0)) state = [0, 0, 0, 1, 0, 0, 0] for _ in range(10): expect = eca.update(np.copy(state)) got = reca.update(state) self.assertTrue(np.array_equal(expect, got))
def test_update_values_index_clash(self): eca = ECA(30, 5) with self.assertRaises(ValueError): eca.update([0, 0, 0, 0, 0], index=0, values={0: 1}) with self.assertRaises(ValueError): eca.update([0, 0, 0, 0, 0], index=1, values={1: 0}) with self.assertRaises(ValueError): eca.update([0, 0, 0, 0, 0], index=1, values={0: 0, 1: 0})
def test_update_pin_index_clash(self): eca = ECA(30, 2) with self.assertRaises(ValueError): eca.update([0, 0], index=0, pin=[1]) with self.assertRaises(ValueError): eca.update([0, 0], index=1, pin=[1]) with self.assertRaises(ValueError): eca.update([0, 0], index=1, pin=[0, 1])
def test_update_index_numpy(self): eca = ECA(30, 5, (1, 1)) lattice = np.asarray([0, 0, 0, 0, 0]) eca.update(lattice, index=0) self.assertTrue(np.array_equal([1, 0, 0, 0, 0], lattice)) lattice = np.asarray([0, 0, 0, 0, 0]) eca.update(lattice, index=1) self.assertTrue(np.array_equal([0, 0, 0, 0, 0], lattice)) lattice = np.asarray([0, 0, 1, 0, 0]) eca.update(lattice, index=1) self.assertTrue(np.array_equal([0, 1, 1, 0, 0], lattice))
def test_update_index(self): eca = ECA(30, 5, (1, 1)) lattice = [0, 0, 0, 0, 0] eca.update(lattice, index=0) self.assertEqual([1, 0, 0, 0, 0], lattice) lattice = [0, 0, 0, 0, 0] eca.update(lattice, index=1) self.assertEqual([0, 0, 0, 0, 0], lattice) lattice = [0, 0, 1, 0, 0] eca.update(lattice, index=1) self.assertEqual([0, 1, 1, 0, 0], lattice)
def test_update_numpy(self): eca = ECA(30, 1, (0, 1)) lattice = np.asarray([0]) eca.update(lattice) self.assertTrue(np.array_equal([1], lattice)) eca.size = 2 lattice = np.asarray([0, 0]) eca.update(lattice) self.assertTrue(np.array_equal([0, 1], lattice)) eca.size = 5 lattice = [0, 0, 1, 0, 0] eca.update(lattice) self.assertTrue(np.array_equal([0, 1, 1, 1, 1], lattice)) eca.update(lattice) self.assertTrue(np.array_equal([1, 1, 0, 0, 0], lattice))
def test_update_open(self): eca = ECA(30, 1, (0, 1)) lattice = [0] eca.update(lattice) self.assertEqual([1], lattice) eca.size = 2 lattice = [0, 0] eca.update(lattice) self.assertEqual([0, 1], lattice) eca.size = 5 lattice = [0, 0, 1, 0, 0] eca.update(lattice) self.assertEqual([0, 1, 1, 1, 1], lattice) eca.update(lattice) self.assertEqual([1, 1, 0, 0, 0], lattice)
def test_update_invalid_values(self): eca = ECA(30, 5) with self.assertRaises(ValueError): eca.update([0, 0, 0, 0, 0], values={0: 2}) with self.assertRaises(ValueError): eca.update([0, 0, 0, 0, 0], values={0: -1})
def test_update_values_none(self): eca = ECA(30, 5) xs = [0, 0, 1, 0, 0] self.assertEqual([0, 1, 1, 1, 0], eca.update(xs, values=None)) self.assertEqual([1, 1, 0, 0, 1], eca.update(xs, values={}))
def test_update_pin_none(self): eca = ECA(30, 5) xs = [0, 0, 1, 0, 0] self.assertEqual([0, 1, 1, 1, 0], eca.update(xs, pin=None)) self.assertEqual([1, 1, 0, 0, 1], eca.update(xs, pin=[]))
def test_invalid_lattice_state_update(self): eca = ECA(30, 3) with self.assertRaises(ValueError): eca.update([-1, 0, 1]) with self.assertRaises(ValueError): eca.update([1, 0, -1]) with self.assertRaises(ValueError): eca.update([2, 0, 0]) with self.assertRaises(ValueError): eca.update([1, 0, 2]) with self.assertRaises(ValueError): eca.update([[1], [0], [2]]) with self.assertRaises(ValueError): eca.update("101")