Exemple #1
0
    def test_invalid_size(self):
        eca = ECA(30, 5)

        eca.size = 8

        with self.assertRaises(ValueError):
            eca.size = -1

        with self.assertRaises(ValueError):
            eca.size = 0

        with self.assertRaises(TypeError):
            eca.size = "5"
Exemple #2
0
    def test_transitions_eca(self):
        net = ECA(30, 1)
        self.assertEqual([0, 0], list(net.transitions))

        net.size = 2
        self.assertEqual([0, 1, 2, 0], list(net.transitions))

        net.size = 3
        self.assertEqual([0, 7, 7, 1, 7, 4, 2, 0], list(net.transitions))

        net.size = 10
        trans = net.transitions
        self.assertEqual(1024, len(trans))
        self.assertEqual([0, 515, 7, 517, 14, 525, 11,
                          521, 28, 543], list(trans[:10]))
        self.assertEqual([18, 16, 13, 14, 10, 8, 7, 4, 2, 0],
                         list(trans[-10:]))
Exemple #3
0
    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))
Exemple #4
0
    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)