def test(): """ Verify that the mean operator works as expected """ # externals import statistics # get the node class from p2.calc.Node import Node as node # make some nodes nodes = [node.variable(value=v) for v in range(0, 100, 10)] # construct a node that computes their mean s = node.mean(operands=nodes) # check the current value assert s.getValue() == statistics.mean(range(0, 100, 10)) # adjust the values for node, value in zip(nodes, range(0, 200, 20)): node.setValue(value) # check again assert s.getValue() == statistics.mean(range(0, 200, 20)) # all done return
def test(): """ Verify that the product operator works as expected """ # externals import functools import operator # get the node class from p2.calc.Node import Node as node # make some nodes nodes = [node.variable(value=v) for v in range(0, 100, 10)] # construct a node that computes their product s = node.product(operands=nodes) # check the current value assert s.getValue() == functools.reduce(operator.mul, range(0, 100, 10)) # adjust the values for node, value in zip(nodes, range(0, 200, 20)): node.setValue(value) # check again assert s.getValue() == functools.reduce(operator.mul, range(0, 100, 10)) # all done return