当前位置: 首页>>代码示例>>Python>>正文


Python Neuron.way_to_go方法代码示例

本文整理汇总了Python中neuron.Neuron.way_to_go方法的典型用法代码示例。如果您正苦于以下问题:Python Neuron.way_to_go方法的具体用法?Python Neuron.way_to_go怎么用?Python Neuron.way_to_go使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在neuron.Neuron的用法示例。


在下文中一共展示了Neuron.way_to_go方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestNeuron

# 需要导入模块: from neuron import Neuron [as 别名]
# 或者: from neuron.Neuron import way_to_go [as 别名]
class TestNeuron(TestCase):

    def setUp(self):
        self.max_length = settings.MAX_PATH_LENGTH
        self.origin_coor = (0, 0)
        self.origin_node = Node(self.origin_coor, 4)
        self.neuron = Neuron(self.origin_node)

    def test_init(self):
        '''Test initiate of neuron.'''
        self.assertEqual(self.neuron.vertex, self.origin_node.connections)
        self.assertFalse(self.neuron.boundary_nodes)
        self.assertFalse(self.neuron.paths)
        self.assertFalse(self.neuron.boundary_paths)
        self.assertEqual(self.neuron.nodes, [self.origin_node])

    def test_hands(self):
        '''Number of hands'''
        if self.neuron.vertex != 6:
            self.assertEqual(self.neuron.hands, self.neuron.vertex)
        # Hands test for neuron with 6 connections origin node.
        node6 = Node(self.origin_coor, 6)
        neuron6 = Neuron(node6)
        hands = []
        '''The probability that neuron.hands only give 2 unique values in
        40 calls is less than 0.00000001'''
        for i in range(40):
            hands.append(neuron6.hands)
        hands = set(hands)
        self.assertEqual(hands, set([4, 5, 6]))

    def test_born(self):
        '''Test for born method of neuron.
        After born, a neuron has several boundary_nodes and the same number
        of boundary_paths.'''

        self.neuron.born()

        if self.neuron.vertex != 6:
            # Neighbours are now boundary nodes.
            self.assertEqual(self.neuron.boundary_nodes, self.neuron.origin.neighbours)
            # Number of boundary paths is the same with vertex number.
            self.assertEqual(len(self.neuron.boundary_paths), self.neuron.vertex)
            # Nodes used by boundary paths.
            path_nodes = [path.origin for path in self.neuron.boundary_paths] +\
                [path.dest for path in self.neuron.boundary_paths]
            # Remove duplicated nodes.
            path_nodes = set(path_nodes)
            # Nodes used by boundary paths are boundary nodes plus origin node.
            self.assertEqual(len(path_nodes), self.neuron.vertex + 1)

        # All boundary_paths are now 0.
        self.assertTrue(all([x.length == 0 for x in self.neuron.boundary_paths]))

    def test_grow(self):
        '''Test for grow function. Grow for 1 and 2 steps.'''
        # Born first to determine grow directions.
        self.neuron.born()
        # Grow for one step.
        self.neuron.grow()
        self.assertTrue(all([x.length == settings.GROW_SPEED for x in self.neuron.boundary_paths]))

        # Grow for another 2 steps.
        for i in range(2):
            self.neuron.grow()
        self.assertTrue(all([x.length == settings.GROW_SPEED*3 for x in self.neuron.boundary_paths]))

    def test_way_to_go_no_way(self):
        '''No way available.'''

        # Node coors for neuron.
        node_coors = [(0, 1), (-1, 1), (-2, 1), (-2, 0), (-2, -1), (-1, -1), (-1, 0)]
        # Test coordinates.
        test = (-1, 0)
        # Assign nodes to self.neuron
        for x in node_coors:
            node = Node([y*self.max_length for y in x], 4)
            self.neuron.nodes.append(node)
        test_node = Node([y*self.max_length for y in test], 4)
        # Assert no way available.
        self.assertFalse(self.neuron.way_to_go(test_node, True))

    def test_way_to_go_one_way(self):
        '''Only one way available.'''

        # Node coordinates to be assigned.
        node_coors = [(0, 1), (0, 2), (-1, 2), (-2, 2), (-2, 1), (-2, 0), (-2, -1), (-1, -1), (-1, 0)]
        # Test coordinates.
        test = (-1, 0)
        # Assign nodes to self.neuron
        for x in node_coors:
            node = Node([y*self.max_length for y in x], 4)
            self.neuron.nodes.append(node)
        test_node = Node([y*self.max_length for y in test], 4)
        # Assert only one way, the only way is (-1, 1)
        target = Node([y*self.max_length for y in (-1, 1)], 4)
        self.assertEqual(self.neuron.way_to_go(test_node, True), [target])

    def test_clean(self):
        '''Test for clean to update boundary conditions.'''
#.........这里部分代码省略.........
开发者ID:mikkkee,项目名称:neuron,代码行数:103,代码来源:tests.py


注:本文中的neuron.Neuron.way_to_go方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。