Sha256: 3ecaf1ce7ec5c85ec1dcbbedcc2962d853c223024008e68d496cede0c14222d9

Contents?: true

Size: 1.71 KB

Versions: 30

Compression:

Stored size: 1.71 KB

Contents

"""Test compiler changes for unary ops (+, -, ~) introduced in Python 2.2"""

import unittest
from test_support import run_unittest

class UnaryOpTestCase(unittest.TestCase):

    def test_negative(self):
        self.assert_(-2 == 0 - 2)
        self.assert_(-0 == 0)
        self.assert_(--2 == 2)
        self.assert_(-2L == 0 - 2L)
        self.assert_(-2.0 == 0 - 2.0)
        self.assert_(-2j == 0 - 2j)

    def test_positive(self):
        self.assert_(+2 == 2)
        self.assert_(+0 == 0)
        self.assert_(++2 == 2)
        self.assert_(+2L == 2L)
        self.assert_(+2.0 == 2.0)
        self.assert_(+2j == 2j)

    def test_invert(self):
        self.assert_(-2 == 0 - 2)
        self.assert_(-0 == 0)
        self.assert_(--2 == 2)
        self.assert_(-2L == 0 - 2L)

    def test_no_overflow(self):
        nines = "9" * 32
        self.assert_(eval("+" + nines) == eval("+" + nines + "L"))
        self.assert_(eval("-" + nines) == eval("-" + nines + "L"))
        self.assert_(eval("~" + nines) == eval("~" + nines + "L"))

    def test_negation_of_exponentiation(self):
        # Make sure '**' does the right thing; these form a
        # regression test for SourceForge bug #456756.
        self.assertEqual(-2 ** 3, -8)
        self.assertEqual((-2) ** 3, -8)
        self.assertEqual(-2 ** 4, -16)
        self.assertEqual((-2) ** 4, 16)

    def test_bad_types(self):
        for op in '+', '-', '~':
            self.assertRaises(TypeError, eval, op + "'a'")
            self.assertRaises(TypeError, eval, op + "u'a'")

        self.assertRaises(TypeError, eval, "~2j")
        self.assertRaises(TypeError, eval, "~2.0")


def test_main():
    run_unittest(UnaryOpTestCase)


if __name__ == "__main__":
    test_main()

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
rubyfox-server-2.12.1.0 lib/rubyfox/server/data/lib/Lib/test/test_unary.py
rubyfox-server-2.11.1.0 lib/rubyfox/server/data/lib/Lib/test/test_unary.py
rubyfox-server-2.9.2.0 lib/rubyfox/server/data/lib/Lib/test/test_unary.py
rubyfox-server-2.9.1.0 lib/rubyfox/server/data/lib/Lib/test/test_unary.py
rubyfox-server-2.9.0.0 lib/rubyfox/server/data/lib/Lib/test/test_unary.py
rubyfox-server-2.8.4.0 lib/rubyfox/server/data/lib/Lib/test/test_unary.py
rubyfox-server-2.8.0.1 lib/rubyfox/server/data/lib/Lib/test/test_unary.py
rubyfox-server-2.8.0.0 lib/rubyfox/server/data/lib/Lib/test/test_unary.py
rubyfox-server-2.3.0.0 lib/rubyfox/server/data/lib/Lib/test/test_unary.py
rubyfox-server-2.3.0.pre2 lib/rubyfox/server/data/lib/Lib/test/test_unary.py