def test(): """ Exercise basic arithmetic operations among literals """ # get the base node from the {calc} package from p2.calc.Node import Node as node # make a couple of literals l1 = node.literal(value=1) l2 = node.literal(value=2) # basic arithmetic among literals assert (l1 + l2).getValue() == 3 assert (l1 - l2).getValue() == -1 assert (l1 * l2).getValue() == 2 assert (l1 / l2).getValue() == 0.5 assert (l1**l2).getValue() == 1 assert (l1 % l2).getValue() == 1 # let the {algebra} build the second literal assert (l1 + 2).getValue() == 3 assert (l1 - 2).getValue() == -1 assert (l1 * 2).getValue() == 2 assert (l1 / 2).getValue() == 0.5 assert (l1**2).getValue() == 1 assert (l1 % 2).getValue() == 1 # all done return
def test(): """ Exercise the interface of operators """ # get the base node from the {calc} package from p2.calc.Node import Node as node # use an expression make an operator operator = 2 * node.literal(value=1) # access the value assert operator.getValue() == 2 # attempt to try: # set the value operator.setValue(value=1) # which should fail assert False, "unreachable" # because there is no base with an implementation except AttributeError as error: # all good pass # all done return
def test(): """ Exercise the interface of literals """ # get the base node from the {calc} package from p2.calc.Node import Node as node # make a literal literal = node.literal(value=0) # access the value assert literal.getValue() == 0 # attempt to try: # set the value literal.setValue(value=1) # which should fail assert False, "unreachable" # because {const} is protecting it except NotImplementedError as error: # all good pass # all done return