File: ctruthtests.pyx

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (101 lines) | stat: -rw-r--r-- 1,548 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
def test_ptr():
    """
    >>> test_ptr()
    False
    """
    cdef void* p = NULL
    if p:
        return True
    else:
        return False

def test_ptr2():
    """
    >>> test_ptr2()
    2
    """
    cdef char* p1 = NULL
    cdef char* p2 = NULL
    p1 += 1

    if p1 and p2:
        return 1
    elif p1 or p2:
        return 2
    else:
        return 3

def test_int(int i):
    """
    >>> test_int(0)
    False
    >>> test_int(1)
    True
    """
    if i:
        return True
    else:
        return False

def test_short(short i):
    """
    >>> test_short(0)
    False
    >>> test_short(1)
    True
    """
    if i:
        return True
    else:
        return False

def test_Py_ssize_t(Py_ssize_t i):
    """
    >>> test_Py_ssize_t(0)
    False
    >>> test_Py_ssize_t(1)
    True
    """
    if i:
        return True
    else:
        return False

cdef class TestExtInt:
    cdef int i
    def __init__(self, i): self.i = i

def test_attr_int(TestExtInt e):
    """
    >>> test_attr_int(TestExtInt(0))
    False
    >>> test_attr_int(TestExtInt(1))
    True
    """
    if e.i:
        return True
    else:
        return False

ctypedef union _aux:
    size_t i
    void *p

cdef class TestExtPtr:
    cdef void* p
    def __init__(self, int i):
        cdef _aux aux
        aux.i = i
        self.p = aux.p

def test_attr_ptr(TestExtPtr e):
    """
    >>> test_attr_ptr(TestExtPtr(0))
    False
    >>> test_attr_ptr(TestExtPtr(1))
    True
    """
    if e.p:
        return True
    else:
        return False