示例#1
0
 def test_transitions_fixed_sized(self):
     """
     ``transitions`` should raise an error if ``net`` is fixed sized and
     ``size`` is not ``None``
     """
     with self.assertRaises(ValueError):
         transitions(MockFixedSizedNetwork, size=3)
示例#2
0
 def test_transitions_not_fixed_sized(self):
     """
     ``transitions`` should raise an error if ``net`` is not fixed sized
     and ``size`` is ``None``
     """
     with self.assertRaises(ValueError):
         transitions(ECA(30), size=None)
示例#3
0
    def test_transitions_eca_encoded(self):
        """
        test ``transitions`` on ECAs; encoding the states
        """
        rule30 = ECA(30)

        got = transitions(rule30, size=1, encode=True)
        self.assertEqual([0, 0], got)

        got = transitions(rule30, size=2, encode=True)
        self.assertEqual([0, 1, 2, 0], got)

        got = transitions(rule30, size=3, encode=True)
        self.assertEqual([0, 7, 7, 1, 7, 4, 2, 0], got)
示例#4
0
    def test_transitions_eca(self):
        """
        test ``transitions`` on ECAs; encoding the states
        """
        rule30 = ECA(30)

        got = transitions(rule30, size=1)
        self.assertEqual([[0], [0]], got)

        got = transitions(rule30, size=2)
        self.assertEqual([[0, 0], [1, 0], [0, 1], [0, 0]], got)

        got = transitions(rule30, size=3)
        self.assertEqual([[0, 0, 0], [1, 1, 1], [1, 1, 1], [1, 0, 0],
                          [1, 1, 1], [0, 0, 1], [0, 1, 0], [0, 0, 0]], got)
示例#5
0
 def test_transitions_logicnetwork_encoded(self):
     """
     test `transitions` on `LogicNetwork`s, states encoded
     """
     net = LogicNetwork([((1, ), {'0', '1'}), ((0, ), {'1'})])
     got = transitions(net, encode=True)
     self.assertEqual([1, 3, 1, 3], got)
示例#6
0
 def test_transitions_logicnetwork(self):
     """
     test `transitions` on `LogicNetwork`s
     """
     net = LogicNetwork([((1, ), {'0', '1'}), ((0, ), {'1'})])
     got = transitions(net)
     self.assertEqual([[1, 0], [1, 1], [1, 0], [1, 1]], got)
示例#7
0
    def test_transitions_wtnetwork_encoded(self):
        """
        test ``transitions`` on WTNetworks; encoding the states
        """
        net = WTNetwork(weights=[[1, 0], [-1, 1]],
                        thresholds=[0.5, 0.0],
                        theta=WTNetwork.positive_threshold)

        got = transitions(net, encode=True)
        self.assertEqual([2, 1, 2, 3], got)
示例#8
0
    def test_transitions_wtnetwork(self):
        """
        test ``transitions`` on WTNetworks
        """
        net = WTNetwork(weights=[[1, 0], [-1, 1]],
                        thresholds=[0.5, 0.0],
                        theta=WTNetwork.positive_threshold)

        got = transitions(net)
        self.assertEqual([[0, 1], [1, 0], [0, 1], [1, 1]], got)
示例#9
0
 def test_transitions_not_network(self):
     """
     ``transitions`` should raise a type error if ``net`` is not a network
     """
     with self.assertRaises(TypeError):
         transitions(MockObject(), 5)