示例#1
0
    def test__cmp__(self):
        n = NUMBER(0, lineno=1)
        m = NUMBER(1, lineno=2)

        self.assertNotEqual(n, m)
        self.assertEqual(n, n)

        self.assertNotEqual(n, 2)
        self.assertEqual(n, 0)
        self.assertGreater(n, -1)
        self.assertLess(n, 1)

        self.assertGreater(m, n)
        self.assertLess(n, m)
示例#2
0
    def test__init__(self):
        self.assertRaises(AssertionError, NUMBER, 0, lineno=None)
        self.assertRaises(AssertionError, NUMBER, 0, lineno=1, type_='')

        n = NUMBER(0, lineno=1)
        self.assertEqual(n.type_, BASICTYPE(TYPE.ubyte))

        n = NUMBER(-1, lineno=1)
        self.assertEqual(n.type_, BASICTYPE(TYPE.byte_))

        n = NUMBER(256, lineno=1)
        self.assertEqual(n.type_, BASICTYPE(TYPE.uinteger))

        n = NUMBER(-256, lineno=1)
        self.assertEqual(n.type_, BASICTYPE(TYPE.integer))
示例#3
0
    def setUp(self):
        zxbpp.init()
        self.t = TYPECAST(Type.float_, NUMBER(3, lineno=1), lineno=2)

        if 'stderr' in OPTIONS:
            del OPTIONS.stderr
        OPTIONS.add_option('stderr', type_=None, default_value=StringIO())
        OPTIONS.hide_warning_codes = True
示例#4
0
    def test__cmp__const(self):
        n = NUMBER(0, lineno=1)
        m = CONST(NUMBER(1, lineno=2), lineno=2)
        m2 = CONST(NUMBER(0, lineno=3), lineno=3)

        self.assertNotEqual(n, m)
        self.assertEqual(n, n)

        self.assertNotEqual(n, 2)
        self.assertEqual(n, 0)
        self.assertGreater(n, -1)
        self.assertLess(n, 1)

        self.assertGreater(m, n)
        self.assertLess(n, m)
        self.assertEqual(n, m2)
        self.assertEqual(m2, n)
    def setUp(self):
        zxbpp.init()
        self.t = TYPECAST(Type.float_, NUMBER(3, lineno=1), lineno=2)

        if 'stderr' in OPTIONS:
            del OPTIONS.stderr
        OPTIONS(Action.ADD, name='stderr', default=StringIO())
        OPTIONS.hide_warning_codes = True
示例#6
0
 def test__eq__2(self):
     n = NUMBER(1, lineno=1)
     b = BLOCK.make_node(n)
     self.assertEqual(b, b)
     q = BLOCK()
     self.assertNotEqual(b, q)
     self.assertNotEqual(q, None)
     self.assertNotEqual(None, q)
     self.assertNotEqual(q, 'STRING')
示例#7
0
 def test__le__val_num(self):
     b = NUMBER(3, 0)
     self.assertLessEqual(2, b)
示例#8
0
 def test__mod__val_num(self):
     b = NUMBER(3, 0)
     self.assertEqual((5 % b).t, '2')
示例#9
0
 def test__sub__num_const(self):
     a = NUMBER(1, 0)
     b = CONST(NUMBER(2, 0), 0)
     self.assertEqual((a - b).t, '-1')
示例#10
0
 def test__radd__num_value(self):
     a = NUMBER(1, 0)
     self.assertEqual((2 + a).t, '3')
示例#11
0
 def test__rmul__num_const(self):
     a = NUMBER(3, 0)
     b = CONST(NUMBER(2, 0), 0)
     self.assertEqual((b * a).t, '6')
示例#12
0
 def test__ge__num_num(self):
     a = NUMBER(4, 0)
     b = NUMBER(3, 0)
     self.assertGreaterEqual(a, b)
示例#13
0
 def test__rdiv__num_value(self):
     a = NUMBER(-2, 0)
     self.assertEqual((3.0 / a).t, '-1.5')
示例#14
0
 def test__rdiv__num_const(self):
     a = CONST(NUMBER(-3, 0), 0)
     b = NUMBER(2, 0)
     self.assertEqual((a / b).t, str(a.expr.value / b.value))
示例#15
0
 def test__div__num_value(self):
     a = NUMBER(3, 0)
     self.assertEqual((a / -2.0).t, '-1.5')
示例#16
0
 def test__div__num_num(self):
     a = NUMBER(3, 0)
     b = NUMBER(-2, 0)
     self.assertEqual((a / b).t, str(a.value / b.value))
示例#17
0
 def test__rmul__num_value(self):
     a = NUMBER(3, 0)
     self.assertEqual((2 * a).t, '6')
示例#18
0
 def test__le__num_num(self):
     a = NUMBER(2, 0)
     b = NUMBER(3, 0)
     self.assertLessEqual(a, b)
示例#19
0
 def test__ge__val_num(self):
     b = NUMBER(1, 0)
     self.assertGreaterEqual(2, b)
示例#20
0
 def test__add__num_num(self):
     a = NUMBER(1, 0)
     b = NUMBER(2, 0)
     self.assertEqual((a + b).t, '3')
示例#21
0
 def test__bor__val_num(self):
     b = NUMBER(5, 0)
     self.assertEqual((3 | b).t, '7')
示例#22
0
 def test__mul__num_num(self):
     a = NUMBER(3, 0)
     b = NUMBER(2, 0)
     self.assertEqual((a * b).t, '6')
示例#23
0
 def test__t(self):
     n = NUMBER(3.14, 1)
     self.assertEqual(n.t, '3.14')
示例#24
0
 def test__bor__num_val(self):
     b = NUMBER(5, 0)
     self.assertEqual((b | 3).t, '7')
示例#25
0
 def test__radd__num_const(self):
     a = NUMBER(1, 0)
     b = CONST(NUMBER(2, 0), 0)
     self.assertEqual((b + a).t, '3')
示例#26
0
 def test__band__num_val(self):
     b = NUMBER(5, 0)
     self.assertEqual((b & 3).t, '1')
示例#27
0
 def test__sub__num_num(self):
     a = NUMBER(1, 0)
     b = NUMBER(2, 0)
     self.assertEqual((a - b).t, '-1')
示例#28
0
 def test__band__val_num(self):
     b = NUMBER(5, 0)
     self.assertEqual((3 & b).t, '1')
示例#29
0
 def test__sub__num_value(self):
     a = NUMBER(1, 0)
     self.assertEqual((a - 2).t, '-1')
示例#30
0
 def test__mod__num_val(self):
     b = NUMBER(5, 0)
     self.assertEqual((b % 3).t, '2')