Ejemplo n.º 1
0
def test_if_false():
    st = If(Variable("x"), Assign("y", Number(1)), DoNothing())
    en = {"x": Boolean(False)}
    while st.reducible:
        st, en = st.reduce(en)
    assert st == DoNothing()
    assert en["x"] == Boolean(False)
Ejemplo n.º 2
0
 def test_if_false(self):
     st = If(Variable("x"), Assign("y", Number(1)), DoNothing())
     en = {"x": Boolean(False)}
     while st.reducible:
         st, en = st.reduce(en)
     self.assertEqual(st, DoNothing())
     self.assertEqual(en["x"], Boolean(False))
Ejemplo n.º 3
0
 def test_if_true(self):
     st = If(Variable("x"), Assign("y", Number(1)), Assign("y", Number(2)))
     self.assertEqual(str(st), "if (x) { y = 1 } else { y = 2 }")
     en = {"x": Boolean(True)}
     while st.reducible:
         st, en = st.reduce(en)
     self.assertEqual(en["y"], Number(1))
     self.assertEqual(en["x"], Boolean(True))
Ejemplo n.º 4
0
def test_if_true():
    st = If(Variable("x"), Assign("y", Number(1)), Assign("y", Number(2)))
    assert str(st) == "if (x) { y = 1 } else { y = 2 }"
    en = {"x": Boolean(True)}
    while st.reducible:
        st, en = st.reduce(en)
    assert en["y"] == Number(1)
    assert en["x"] == Boolean(True)
Ejemplo n.º 5
0
 def test_if(self):
     st = If(
         LessThan(Variable("x"), Number(5)),
         Assign("x", Number(2)),
         Assign("x", Multiply(Variable("x"), Variable("x"))),
     )
     self.assertEqual(eval(st.to_python)({"x": 1}), {"x": 2})
Ejemplo n.º 6
0
def test_if():
    st = If(
        LessThan(Variable("x"), Number(5)),
        Assign("x", Number(2)),
        Assign("x", Multiply(Variable("x"), Variable("x"))),
    )
    assert eval(st.to_python)({"x": 1}) == {"x": 2}
Ejemplo n.º 7
0
    def test_if_true_and_false(self):
        st = If(
            LessThan(Variable("x"), Number(5)),
            Assign("x", Number(2)),
            Assign("x", Multiply(Variable("x"), Variable("x"))),
        )
        en = st.evaluate({"x": Number(2)})
        self.assertEqual(en["x"], Number(2))

        st = If(
            LessThan(Variable("x"), Number(5)),
            Assign("x", Number(2)),
            Assign("x", Multiply(Variable("x"), Variable("x"))),
        )
        en = st.evaluate({"x": Number(10)})
        self.assertEqual(en["x"], Number(100))
Ejemplo n.º 8
0
def test_if_true_and_false():
    st = If(
        LessThan(Variable("x"), Number(5)),
        Assign("x", Number(2)),
        Assign("x", Multiply(Variable("x"), Variable("x"))),
    )
    en = st.evaluate({"x": Number(2)})
    assert en["x"] == Number(2)

    st = If(
        LessThan(Variable("x"), Number(5)),
        Assign("x", Number(2)),
        Assign("x", Multiply(Variable("x"), Variable("x"))),
    )
    en = st.evaluate({"x": Number(10)})
    assert en["x"] == Number(100)