diff options
author | Damien George <damien.p.george@gmail.com> | 2014-01-19 17:41:01 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-01-19 17:41:01 +0000 |
commit | 5f7e8dc176661b49e12a0d8425101799ff176d19 (patch) | |
tree | 0fd3daa844300d62a3836b5bb16c3c7be2b875cb /tests/basics/int1.py | |
parent | b2ebb161d494864cdbee05ee8b74a775845e238e (diff) | |
parent | db796ef84d1737edc4ee44f1b53ff0c1fddb349c (diff) | |
download | micropython-5f7e8dc176661b49e12a0d8425101799ff176d19.tar.gz micropython-5f7e8dc176661b49e12a0d8425101799ff176d19.zip |
Merge branch 'master' of github.com:micropython/micropython
Diffstat (limited to 'tests/basics/int1.py')
-rw-r--r-- | tests/basics/int1.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/basics/int1.py b/tests/basics/int1.py new file mode 100644 index 0000000000..4ce0f9e70c --- /dev/null +++ b/tests/basics/int1.py @@ -0,0 +1,74 @@ +print(int(0)) +print(int(1)) +print(int(+1)) +print(int(-1)) + +print(int('0')) +print(int('+0')) +print(int('-0')) +print(int('1')) +print(int('+1')) +print(int('-1')) +print(int('01')) +print(int('9')) +print(int('10')) +print(int('+10')) +print(int('-10')) +print(int('12')) +print(int('-12')) +print(int('99')) +print(int('100')) +print(int('314')) +print(int(' 314')) +print(int('314 ')) +print(int(' \t\t 314 \t\t ')) +print(int(' 1 ')) +print(int(' -3 ')) + +print(int('0', 10)) +print(int('1', 10)) +print(int(' \t 1 \t ', 10)) +print(int('11', 10)) +print(int('11', 16)) +print(int('11', 8)) +print(int('11', 2)) +print(int('11', 36)) +print(int('0o123', 0)) +print(int('8388607')) +print(int('0x123', 16)) +print(int('0X123', 16)) +print(int('0o123', 8)) +print(int('0O123', 8)) +print(int('0123', 8)) +print(int('0b100', 2)) +print(int('0B100', 2)) +print(int('0100', 2)) +print(int(' \t 0o12', 8)) +print(int('0o12 \t ', 8)) + + +def test(value, base): + try: + print(int(value, base)) + except ValueError: + print('ValueError') + + +test('x', 0) +test('1x', 0) +test(' 1x', 0) +test(' 1' + chr(2) + ' ', 0) +test('', 0) +test(' ', 0) +test(' \t\t ', 0) +test("\u0200", 0) +test('0x', 16) +test('0x', 0) +test('0o', 8) +test('0o', 0) +test('0b', 2) +test('0b', 0) +test('0b2', 2) +test('0o8', 8) +test('0xg', 16) +test('1 1', 16) |