better bint type printing, tests
authorRobert Bradshaw <robertwb@math.washington.edu>
Sat, 2 Apr 2011 21:33:02 +0000 (14:33 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sat, 2 Apr 2011 21:33:02 +0000 (14:33 -0700)
Cython/Compiler/PyrexTypes.py
tests/run/bint.pyx

index b62a076418faf4b164b6ced63090b9775ddd0a31..45e9af08894b5198ffbceb2e20b1f1c2ca199dac 100755 (executable)
@@ -925,6 +925,9 @@ class CBIntType(CIntType):
     def __repr__(self):
         return "<CNumericType bint>"
 
+    def __str__(self):
+        return 'bint'
+
 
 class CPyUCS4IntType(CIntType):
     # Py_UCS4
index 8f498825d992da87930a60cc927511278def21c1..86502043c10f3efe8db045df59049d1ce9d6b084 100644 (file)
@@ -1,23 +1,41 @@
-cdef test(bint value):
-    print value
+from cython cimport typeof
 
-def call_test():
+def test(bint value):
     """
-    >>> call_test()
-    False
+    >>> test(True)
     True
+    >>> test(False)
+    False
+    >>> test(None)
+    False
+
+    >>> test(0)
     False
+    >>> test(1)
+    True
+    >>> test(-1)
     True
+    >>> test(100)
     True
+
+    >>> test(0.0)
+    False
+    >>> test(0.1)
     True
+
+    >>> test([])
+    False
+    >>> test([1, 2, 3])
     True
     """
-    test(False)
-    test(True)
-    test(0)
-    test(234)
-    test(-1)
-    x = True
-    test(x)
-    x = 3242
-    test(x)
+    return value
+
+def test_types(bint a):
+    """
+    >>> test_types(None)
+    """
+    cdef bint b = a
+    assert typeof(a) == 'bint', typeof(a)
+    assert typeof(b) == 'bint', typeof(b)
+    c = b
+    assert typeof(c) == 'bint', typeof(c)