コード例 #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)