예제 #1
0
def test_name_lookup_dict():
    numpy.testing.assert_almost_equal(
        evaluator({
            "pi": scipy.constants.pi,
            "golden": scipy.constants.golden
        }).evaluate(ast.parse("pi + golden")),
        scipy.constants.pi + scipy.constants.golden)
예제 #2
0
def test_name_lookup_callback():
  class custom_lookup:
    def __contains__(self, key):
      return key in ["pi", "golden"]
    def __getitem__(self, key):
      if key == "pi":
        return scipy.constants.pi
      elif key == "golden":
        return scipy.constants.golden
      else:
        raise KeyError()
  numpy.testing.assert_almost_equal(evaluator(custom_lookup()).evaluate(ast.parse("pi + golden")), scipy.constants.pi + scipy.constants.golden)
예제 #3
0
def test_name_lookup_callback():
    class custom_lookup:
        def __contains__(self, key):
            return key in ["pi", "golden"]

        def __getitem__(self, key):
            if key == "pi":
                return scipy.constants.pi
            elif key == "golden":
                return scipy.constants.golden
            else:
                raise KeyError()

    numpy.testing.assert_almost_equal(
        evaluator(custom_lookup()).evaluate(ast.parse("pi + golden")),
        scipy.constants.pi + scipy.constants.golden)
예제 #4
0
def test_not():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("not 1")), 0)
예제 #5
0
def test_rshift():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("8 >> 1")), 4)
예제 #6
0
def test_invert():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("~1")), -2)
예제 #7
0
def test_mod():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 % 3")), 2)
예제 #8
0
def test_bitand():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 & 3")), 2)
예제 #9
0
def test_invert():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("~1")), -2)
예제 #10
0
def test_rshift():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("8 >> 1")), 4)
예제 #11
0
def test_div():
  numpy.testing.assert_almost_equal(evaluator().evaluate(ast.parse("2/3")), 2.0/3.0)
예제 #12
0
def test_not():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("not 1")), 0)
예제 #13
0
def test_pow():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2**3")), 8)
예제 #14
0
def test_mult():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2*3")), 6)
예제 #15
0
def test_mod():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 % 3")), 2)
예제 #16
0
def test_lte():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 <= 3")), True)
예제 #17
0
def test_uadd():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("+(2+3)")), 5)
예제 #18
0
def test_sub():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 - 3")), -1)
예제 #19
0
def test_expr_1():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("1+2*3")), 7)
예제 #20
0
def test_bitxor():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 ^ 3")), 1)
예제 #21
0
def test_floordiv():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2//3")), 0)
예제 #22
0
def test_floordiv():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2//3")), 0)
예제 #23
0
def test_uadd():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("+(2+3)")), 5)
예제 #24
0
def test_gte():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 >= 3")), False)
예제 #25
0
def test_div():
    numpy.testing.assert_almost_equal(evaluator().evaluate(ast.parse("2/3")),
                                      2.0 / 3.0)
예제 #26
0
def test_usub():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("-(2+3)")), -5)
예제 #27
0
def test_gte():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 >= 3")),
                               False)
예제 #28
0
def test_expr_1():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("1+2*3")), 7)
예제 #29
0
def test_lte():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 <= 3")), True)
예제 #30
0
def test_boolean_expr_1():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("1 < 2 and 2 < 3")), True)
예제 #31
0
def test_mult():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2*3")), 6)
예제 #32
0
def test_boolean_expr_2():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("1 == 2 or 3 == 2 + 1")), True)
예제 #33
0
def test_pow():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2**3")), 8)
예제 #34
0
def test_name_lookup_dict():
  numpy.testing.assert_almost_equal(evaluator({"pi" : scipy.constants.pi, "golden" : scipy.constants.golden}).evaluate(ast.parse("pi + golden")), scipy.constants.pi + scipy.constants.golden)
예제 #35
0
def test_sub():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 - 3")), -1)
예제 #36
0
def test_bitand():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 & 3")), 2)
예제 #37
0
def test_usub():
    numpy.testing.assert_equal(evaluator().evaluate(ast.parse("-(2+3)")), -5)
예제 #38
0
def test_boolean_expr_2():
    numpy.testing.assert_equal(
        evaluator().evaluate(ast.parse("1 == 2 or 3 == 2 + 1")), True)
예제 #39
0
def test_boolean_expr_1():
    numpy.testing.assert_equal(
        evaluator().evaluate(ast.parse("1 < 2 and 2 < 3")), True)
예제 #40
0
def test_bitxor():
  numpy.testing.assert_equal(evaluator().evaluate(ast.parse("2 ^ 3")), 1)