Пример #1
0
def init_struct(init_value):
    equals_node = EqualsNode()
    d1 = DataSourceNode(init_value)
    d2 = DataSourceNode(init_value)
    BaseNode.connect(d1, equals_node, 'data', 'arg1')
    BaseNode.connect(d2, equals_node, 'data', 'arg2')
    return equals_node, d1, d2
Пример #2
0
def init_gte_struct(d1_init, d2_init):
    greater_than_node = GreaterThanOrEqualNode()
    d1 = DataSourceNode(d1_init)
    d2 = DataSourceNode(d2_init)
    BaseNode.connect(d1, greater_than_node, 'data', 'arg1')
    BaseNode.connect(d2, greater_than_node, 'data', 'arg2')
    return greater_than_node, d1, d2
Пример #3
0
def init_lte_struct(d1_init, d2_init):
    less_than_node = LessThanOrEqualNode()
    d1 = DataSourceNode(d1_init)
    d2 = DataSourceNode(d2_init)
    BaseNode.connect(d1, less_than_node, 'data', 'arg1')
    BaseNode.connect(d2, less_than_node, 'data', 'arg2')
    return less_than_node, d1, d2
Пример #4
0
def init_ne_struct(d1_init, d2_init):
    equals_node = NotEqualsNode()
    d1 = DataSourceNode(d1_init)
    d2 = DataSourceNode(d2_init)
    BaseNode.connect(d1, equals_node, 'data', 'arg1')
    BaseNode.connect(d2, equals_node, 'data', 'arg2')
    return equals_node, d1, d2
Пример #5
0
 def test_node_output(self):
     self.assertEqual(0, IncrementNode().resolve_output('value'))
     self.assertEqual(1, IncrementNode().resolve_output('increment'))
     inc_node = IncrementNode()
     dummy_node = DummyNode()
     BaseNode.connect(inc_node, dummy_node, 'increment', 'in')
     BaseNode.connect(inc_node, dummy_node, 'increment', 'extra')
     self.assertEqual(2, dummy_node.resolve_output('out'))
Пример #6
0
 def test_node_output(self):
     floor_node = FloorNode()
     d_node = DataSourceNode(1.2)
     BaseNode.connect(d_node, floor_node, 'data', 'value')
     self.assertEqual(floor_node.resolve_output('result'), 1)
     d_node.data = 1.8
     self.assertEqual(floor_node.resolve_output('result'), 1)
     d_node.data = -4.4
     self.assertEqual(floor_node.resolve_output('result'), -5)
Пример #7
0
 def test_node_output(self):
     abs_node = AbsoluteValueNode()
     d_node = DataSourceNode(6.5)
     BaseNode.connect(d_node, abs_node, 'data', 'in')
     self.assertEqual(abs_node.resolve_output('result'), 6.5)
     d_node.data = -4.2
     self.assertEqual(abs_node.resolve_output('result'), 4.2)
     d_node.data = 0.
     self.assertEqual(abs_node.resolve_output('result'), 0)
Пример #8
0
 def test_node_output(self):
     ceil_node = CeilNode()
     d_node = DataSourceNode(1.2)
     BaseNode.connect(d_node, ceil_node, 'data', 'value')
     self.assertEqual(ceil_node.resolve_output('result'), 2)
     d_node.data = 1.8
     self.assertEqual(ceil_node.resolve_output('result'), 2)
     d_node.data = -4.4
     self.assertEqual(ceil_node.resolve_output('result'), -4)
Пример #9
0
 def test_node_output(self):
     round_node = RoundNode()
     d_node = DataSourceNode(1.2)
     BaseNode.connect(d_node, round_node, 'data', 'value')
     self.assertEqual(round_node.resolve_output('result'), 1)
     d_node.data = 1.8
     self.assertEqual(round_node.resolve_output('result'), 2)
     d_node.data = -4.4
     self.assertEqual(round_node.resolve_output('result'), -4)
     d_node.data = 4.5
     self.assertEqual(round_node.resolve_output('result'), 5)
Пример #10
0
 def test_and_false(self):
     and_node = AndNode()
     d1 = DataSourceNode(True)
     d2 = DataSourceNode(False)
     BaseNode.connect(d1, and_node, 'data', 'arg1')
     BaseNode.connect(d2, and_node, 'data', 'arg2')
     self.assertFalse(and_node.resolve_output('result'))
     d1.data = False
     self.assertFalse(and_node.resolve_output('result'))
     d2.data = True
     self.assertFalse(and_node.resolve_output('result'))
Пример #11
0
    def __init__(self):
        super().__init__()

        self.declare_input('iter')
        self.declare_input('value')
        self.declare_input('__continue__')
        self.declare_output('value', self.get_output__value, self.deploy_output__value)
        self.declare_output('__continue__', self.get_output____continue__)

        BaseNode.connect(self, self, '__continue__', '__continue__')

        self.state['init'] = False
Пример #12
0
 def test_or_true(self):
     or_node = OrNode()
     d1 = DataSourceNode(True)
     d2 = DataSourceNode(True)
     BaseNode.connect(d1, or_node, 'data', 'arg1')
     BaseNode.connect(d2, or_node, 'data', 'arg2')
     self.assertTrue(or_node.resolve_output('result'))
     d1.data = False
     self.assertTrue(or_node.resolve_output('result'))
     d1.data = True
     d2.data = False
     self.assertTrue(or_node.resolve_output('result'))
Пример #13
0
 def test_node_output(self):
     map_node = MapNode()
     add_node = AddNode()
     BaseNode.connect(DataSourceNode([0, 1, 2, 3, 4]), map_node, 'data',
                      'array')
     BaseNode.connect(map_node, add_node, 'entry', 'arg1')
     BaseNode.connect(map_node, add_node, 'index', 'arg2')
     BaseNode.connect(add_node, map_node, 'result', 'value')
     self.assertEqual([0, 2, 4, 6, 8], map_node.resolve_output('mapped'))
Пример #14
0
    def test_node_output(self):
        reduce_node = ReduceNode()
        BaseNode.connect(DataSourceNode([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
                         reduce_node, 'data', 'array')
        add_node = AddNode()
        BaseNode.connect(reduce_node, add_node, 'accumulator', 'arg1')
        BaseNode.connect(reduce_node, add_node, 'current', 'arg2')
        BaseNode.connect(add_node, reduce_node, 'result', 'accumulator')

        self.assertEqual(45, reduce_node.resolve_output('reduced'))
Пример #15
0
    def test_node_output(self):
        self.assertEqual(
            'no iter',
            node_struct(LoopNode(), [False, 'no iter'],
                        ['iter', 'value']).resolve_output('value'))

        loop_node = LoopNode()
        inc_node = IncrementNode()
        ne_node = NotEqualsNode()
        BaseNode.connect(inc_node, loop_node, 'value', 'value')
        BaseNode.connect(inc_node, ne_node, 'increment', 'arg1')
        BaseNode.connect(DataSourceNode(5), ne_node, 'data', 'arg2')
        BaseNode.connect(ne_node, loop_node, 'result', 'iter')
        self.assertEqual(5, loop_node.resolve_output('value'))
Пример #16
0
 def test_node_output(self):
     self.assertEqual(0, VariableNode().resolve_output('value'))
     self.assertEqual(4, VariableNode(4).resolve_output('value'))
     self.assertEqual(
         4,
         node_struct(VariableNode(), [4],
                     ['value']).resolve_output('update'))
     var_node = VariableNode(1)
     multiply_node = MultiplyNode()
     BaseNode.connect(multiply_node, var_node, 'result', 'value')
     BaseNode.connect(var_node, multiply_node, 'value', 'arg1')
     BaseNode.connect(DataSourceNode(2), multiply_node, 'data', 'arg2')
     self.assertEqual(2, var_node.resolve_output('update'))
     self.assertEqual(4, var_node.resolve_output('update'))
     self.assertEqual(8, var_node.resolve_output('update'))
Пример #17
0
 def test_value(self):
     input_str = 'abcdef123456'
     node = PassThroughNode()
     BaseNode.connect(DataSourceNode(input_str), node, 'data', 'in')
     self.assertEqual(node.resolve_output('out'), input_str)
Пример #18
0
    def test_node_output(self):
        filter_node = FilterNode()
        BaseNode.connect(DataSourceNode([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
                         filter_node, 'data', 'array')
        mod_node = ModulusNode()
        eq_node = EqualsNode()
        BaseNode.connect(filter_node, mod_node, 'entry', 'arg1')
        BaseNode.connect(DataSourceNode(2), mod_node, 'data', 'arg2')
        BaseNode.connect(mod_node, eq_node, 'result', 'arg1')
        BaseNode.connect(DataSourceNode(0), eq_node, 'data', 'arg2')
        BaseNode.connect(eq_node, filter_node, 'result', 'keep')

        self.assertEqual([0, 2, 4, 6, 8],
                         filter_node.resolve_output('filtered'))
Пример #19
0
 def test_node_output(self):
     find_node = FindNode()
     add_node = AddNode()
     eq_node = EqualsNode()
     BaseNode.connect(DataSourceNode([0, 1, 2, 3, 4, 5, 6]), find_node,
                      'data', 'array')
     BaseNode.connect(find_node, add_node, 'entry', 'arg1')
     BaseNode.connect(DataSourceNode(3), add_node, 'data', 'arg2')
     BaseNode.connect(add_node, eq_node, 'result', 'arg1')
     BaseNode.connect(DataSourceNode(7), eq_node, 'data', 'arg2')
     BaseNode.connect(eq_node, find_node, 'result', 'matches')
     self.assertEqual(4, find_node.resolve_output('match'))
Пример #20
0
 def test_and_true(self):
     and_node = AndNode()
     BaseNode.connect(DataSourceNode(True), and_node, 'data', 'arg1')
     BaseNode.connect(DataSourceNode(True), and_node, 'data', 'arg2')
     self.assertTrue(and_node.resolve_output('result'))
Пример #21
0
 def test_or_false(self):
     or_node = OrNode()
     BaseNode.connect(DataSourceNode(False), or_node, 'data', 'arg1')
     BaseNode.connect(DataSourceNode(False), or_node, 'data', 'arg2')
     self.assertFalse(or_node.resolve_output('result'))
Пример #22
0
 def test_not_node_false(self):
     not_node = NotNode()
     BaseNode.connect(DataSourceNode(True), not_node, 'data', 'in')
     self.assertFalse(not_node.resolve_output('out'))
Пример #23
0
def node_struct(node, input_values, input_names):
    for input_value, input_name in zip(input_values, input_names):
        BaseNode.connect(DataSourceNode(input_value), node, 'data', input_name)
    return node
Пример #24
0
def operation_value(node, val1, val2, val1_name='arg1', val2_name='arg2'):
    BaseNode.connect(DataSourceNode(val1), node, 'data', val1_name)
    BaseNode.connect(DataSourceNode(val2), node, 'data', val2_name)
    return node.resolve_output('result')