Ejemplo n.º 1
0
 def test_io(self):
     fin = StringIO.StringIO("Input line 1.\nInput line 2.")
     fout = StringIO.StringIO()
     result = crianza.eval('123 read "howdy" . .', input=fin, output=fout)
     self.assertEqual(result, 123)
     self.assertEqual(fin.getvalue()[fin.tell():], "Input line 2.")
     self.assertEqual(fout.getvalue(), "howdy\nInput line 1.\n")
Ejemplo n.º 2
0
    def _test_arithmetic(self, a, b, op):
        name = {"mul": "*",
                "sub": "-",
                "add": "+",
                "mod": "%",
                "div": "/"}[op.__name__]

        source = "%d %d %s" % (a, b, name)
        self.assertEqual(crianza.eval(source), op(a, b))
Ejemplo n.º 3
0
 def test_eval(self):
     self.assertEqual(crianza.eval("1 2 3 4 5 * * * *"), 120)
     self.assertEqual(crianza.eval("1 2 3 4 5 - - - -"), 3)
     self.assertEqual(crianza.eval("1 2 3 4 5 + + + +"), 15)