summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorxyb <xieyanbo@gmail.com>2014-01-14 21:39:05 +0800
committerxyb <xieyanbo@gmail.com>2014-01-14 21:39:05 +0800
commitc178ea471ee30f32439741181d30d6a89830aabf (patch)
treebbd572854f1491523ab70f122695f511c3d9c265 /tests
parent729e9cce7bd31d3f107a4d6e9498b0fa27119e22 (diff)
Implemented int(str) in UNIX
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/tests/int1.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/basics/tests/int1.py b/tests/basics/tests/int1.py
new file mode 100644
index 000000000..d766216d4
--- /dev/null
+++ b/tests/basics/tests/int1.py
@@ -0,0 +1,54 @@
+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('9'))
+print(int('10'))
+print(int('+10'))
+print(int('-10'))
+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('10', 16))
+print(int('0o123', 0))
+print(int('0x123', 16))
+print(int('0X123', 16))
+print(int('0O123', 8))
+print(int('0B100', 2))
+
+
+def test(value, base):
+ try:
+ print(int(value, base))
+ except ValueError:
+ print('ValueError')
+
+
+test(' 1x', 0)
+test(' 1\02 ', 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)