예제 #1
0
파일: test_reca.py 프로젝트: siyuzhou/Neet
    def test_reca_values_none(self):
        """
        Ensure that values behaves correctly for nil arguments
        """
        reca = RewiredECA(30, size=5)

        xs = [0, 0, 1, 0, 0]
        self.assertEqual([0, 1, 1, 1, 0], reca.update(xs, values=None))
        self.assertEqual([1, 1, 0, 0, 1], reca.update(xs, values={}))
예제 #2
0
파일: test_reca.py 프로젝트: siyuzhou/Neet
    def test_reca_pin_none(self):
        """
        Ensure that pin behaves correctly for nil arguments
        """
        reca = RewiredECA(30, size=5)

        xs = [0, 0, 1, 0, 0]
        self.assertEqual([0, 1, 1, 1, 0], reca.update(xs, pin=None))
        self.assertEqual([1, 1, 0, 0, 1], reca.update(xs, pin=[]))
예제 #3
0
파일: test_reca.py 프로젝트: siyuzhou/Neet
    def test_reca_invalid_values(self):
        """
        Ensure ValueError is raised for invalid values
        """
        reca = RewiredECA(30, size=5)

        with self.assertRaises(ValueError):
            reca.update([0, 0, 0, 0, 0], values={0: 2})

        with self.assertRaises(ValueError):
            reca.update([0, 0, 0, 0, 0], values={0: -1})
예제 #4
0
파일: test_reca.py 프로젝트: siyuzhou/Neet
    def test_reca_invalid_index(self):
        """
        Test for invalid index arguments
        """
        reca = RewiredECA(30, wiring=[
            [0, 4, 1, 2, 3], [0, 1, 2, 3, 4], [0, 2, 3, 4, 5]
        ])

        with self.assertRaises(IndexError):
            reca.update([0, 0, 0, 0, 1], index=6)

        with self.assertRaises(IndexError):
            reca.update([0, 0, 0, 0, 1], index=-6)
예제 #5
0
파일: test_reca.py 프로젝트: siyuzhou/Neet
    def test_reca_index(self):
        """
        Test the index argument
        """
        reca = RewiredECA(30, wiring=[
            [0, 4, 1, 2, 3], [0, 1, 2, 3, 4], [0, 2, 3, 4, 5]
        ])

        state = [0, 0, 0, 0, 1]
        self.assertEqual([0, 0, 0, 1, 1], reca.update(state, index=3))
        self.assertEqual([0, 0, 1, 1, 1], reca.update(state, index=2))
        self.assertEqual([0, 0, 1, 1, 0], reca.update(state, index=-1))
        self.assertEqual([0, 1, 1, 1, 0], reca.update(state, index=1))
        self.assertEqual([0, 1, 0, 1, 0], reca.update(state, index=-3))
        self.assertEqual([0, 1, 0, 1, 0], reca.update(state, index=0))
예제 #6
0
파일: test_reca.py 프로젝트: siyuzhou/Neet
    def test_rewired_network(self):
        """
        Test a non-trivially rewired network
        """
        reca = RewiredECA(30, wiring=[
            [-1, 0, 1, 2, 3], [0, 1, 2, 3, 4], [1, 2, 3, 4, 5]
        ])
        state = [0, 0, 0, 0, 1]
        self.assertEqual([1, 0, 0, 1, 1], reca.update(state))

        reca.wiring[:, :] = [
            [0, 4, 1, 2, 3], [0, 1, 2, 3, 4], [0, 2, 3, 4, 5]
        ]
        state = [0, 0, 0, 0, 1]
        self.assertEqual([0, 1, 0, 1, 1], reca.update(state))
        self.assertEqual([0, 0, 0, 1, 0], reca.update(state))
        self.assertEqual([0, 0, 1, 1, 1], reca.update(state))
        self.assertEqual([0, 0, 1, 0, 0], reca.update(state))
        self.assertEqual([0, 1, 1, 1, 0], reca.update(state))
        self.assertEqual([0, 1, 0, 0, 1], reca.update(state))
        self.assertEqual([0, 0, 1, 1, 1], reca.update(state))
예제 #7
0
파일: test_reca.py 프로젝트: siyuzhou/Neet
 def test_reproduce_open_ecas(self):
     """
     Ensure that RewiredECAs can reproduce open ECAs
     """
     from neet.automata import ECA
     reca = RewiredECA(30, boundary=(1, 0), size=7)
     eca = ECA(30, 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))
예제 #8
0
파일: test_reca.py 프로젝트: siyuzhou/Neet
    def test_reca_values_pin_clash(self):
        """
        Ensure ValueError is raised when pin and values are both provided
        """
        reca = RewiredECA(30, size=5)

        with self.assertRaises(ValueError):
            reca.update([0, 0, 0, 0, 0], pin=[0], values={0: 1})

        with self.assertRaises(ValueError):
            reca.update([0, 0, 0, 0, 0], pin=[1], values={1: 0})

        with self.assertRaises(ValueError):
            reca.update([0, 0, 0, 0, 0], pin=[1], values={0: 0, 1: 0})

        with self.assertRaises(ValueError):
            reca.update([0, 0, 0, 0, 0], pin=[1, 0], values={0: 0, 1: 0})
예제 #9
0
파일: test_reca.py 프로젝트: siyuzhou/Neet
 def test_invalid_lattice_size(self):
     """
     Ensure that update fails when the lattice is the wrong size
     """
     eca = RewiredECA(30, size=3)
     with self.assertRaises(ValueError):
         eca.update([])
     with self.assertRaises(ValueError):
         eca.update([0])
     with self.assertRaises(ValueError):
         eca.update([0, 0])
예제 #10
0
파일: test_reca.py 프로젝트: siyuzhou/Neet
    def test_reca_pin_index_clash(self):
        """
        Ensure ValueError is raised when index and pin are provided
        """
        reca = RewiredECA(30, size=5)

        with self.assertRaises(ValueError):
            reca.update([0, 0, 0, 0, 0], index=0, pin=[1])
        with self.assertRaises(ValueError):
            reca.update([0, 0, 0, 0, 0], index=1, pin=[1])
        with self.assertRaises(ValueError):
            reca.update([0, 0, 0, 0, 0], index=1, pin=[0, 1])
예제 #11
0
파일: test_reca.py 프로젝트: siyuzhou/Neet
    def test_reca_values_index_clash(self):
        """
        Ensure ValueError is raised when index and values are both provided
        """
        reca = RewiredECA(30, size=5)

        with self.assertRaises(ValueError):
            reca.update([0, 0, 0, 0, 0], index=0, values={0: 1})

        with self.assertRaises(ValueError):
            reca.update([0, 0, 0, 0, 0], index=1, values={1: 0})

        with self.assertRaises(ValueError):
            reca.update([0, 0, 0, 0, 0], index=1, values={0: 0, 1: 0})
예제 #12
0
파일: test_reca.py 프로젝트: siyuzhou/Neet
    def test_reca_pin(self):
        """
        Test the pin argument
        """
        reca = RewiredECA(30, wiring=[
            [-1, 4, 1, 2, -1], [0, 1, 2, 3, 4], [0, 2, 3, 4, 5]
        ])

        xs = [0, 0, 1, 0, 0]
        self.assertEqual([0, 0, 1, 1, 0], reca.update(xs, pin=[1]))
        self.assertEqual([0, 1, 1, 1, 0], reca.update(xs, pin=[3]))
        self.assertEqual([0, 1, 1, 1, 0], reca.update(xs, pin=[3, 2]))
        self.assertEqual([0, 1, 0, 1, 0], reca.update(xs, pin=[-2]))

        reca.boundary = (1, 1)
        xs = [0, 0, 1, 0, 0]
        self.assertEqual([1, 0, 1, 0, 0], reca.update(xs, pin=[1, 3]))
        self.assertEqual([1, 1, 1, 0, 0], reca.update(xs, pin=[-2, -5]))
        self.assertEqual([1, 1, 1, 1, 0], reca.update(xs, pin=[0, 2]))
예제 #13
0
파일: test_reca.py 프로젝트: siyuzhou/Neet
    def test_reca_values(self):
        """
        Test the values argument
        """
        reca = RewiredECA(30, wiring=[
            [-1,  4,  1,  2, -1], [0,  1,  2,  3,  4], [0,  2,  3,  4,  5]
        ])

        xs = [0, 0, 1, 0, 0]
        self.assertEqual([1, 1, 1, 1, 0], reca.update(xs, values={0: 1}))
        self.assertEqual([1, 1, 0, 0, 0], reca.update(xs, values={-1: 0}))
        self.assertEqual([1, 1, 1, 1, 1], reca.update(xs, values={-2: 1}))
        self.assertEqual([1, 0, 1, 0, 0], reca.update(
            xs, values={2: 1, -5: 1}))

        reca.boundary = (1, 1)
        xs = [0, 0, 1, 0, 0]
        self.assertEqual([0, 1, 1, 1, 0], reca.update(xs, values={0: 0}))
        self.assertEqual([1, 1, 0, 0, 1], reca.update(xs, values={-1: 1}))
        self.assertEqual([0, 0, 1, 0, 0], reca.update(xs, values={-2: 0}))
        self.assertEqual([0, 1, 0, 1, 0], reca.update(
            xs, values={2: 0, -5: 0}))
예제 #14
0
파일: test_reca.py 프로젝트: siyuzhou/Neet
 def test_invalid_lattice_state(self):
     """
     Ensure that the states of the lattice are binary states
     """
     eca = RewiredECA(30, size=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")