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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
from python_overload_simple_cast import *
class Ai:
def __init__(self, x):
self.x = x
def __int__(self):
return self.x
class Ad:
def __init__(self, x):
self.x = x
def __float__(self):
return self.x
ai = Ai(4)
ad = Ad(5.0)
add = Ad(5.5)
try:
fint(add)
good = 0
except:
good = 1
if not good:
raise RuntimeError, "fint(int)"
if fint(ad) != "fint:int":
raise RuntimeError, "fint(int)"
if fdouble(ad) != "fdouble:double":
raise RuntimeError, "fdouble(double)"
if fint(ai) != "fint:int":
raise RuntimeError, "fint(int)"
if fint(5.0) != "fint:int":
raise RuntimeError, "fint(int)"
if fint(3) != "fint:int":
raise RuntimeError, "fint(int)"
if fint(3.0) != "fint:int":
raise RuntimeError, "fint(int)"
if fdouble(ad) != "fdouble:double":
raise RuntimeError, "fdouble(double)"
if fdouble(3) != "fdouble:double":
raise RuntimeError, "fdouble(double)"
if fdouble(3.0) != "fdouble:double":
raise RuntimeError, "fdouble(double)"
if fid(3, 3.0) != "fid:intdouble":
raise RuntimeError, "fid:intdouble"
if fid(3.0, 3) != "fid:doubleint":
raise RuntimeError, "fid:doubleint"
if fid(ad, ai) != "fid:doubleint":
raise RuntimeError, "fid:doubleint"
if fid(ai, ad) != "fid:intdouble":
raise RuntimeError, "fid:intdouble"
if foo(3) != "foo:int":
raise RuntimeError, "foo(int)"
if foo(3.0) != "foo:double":
raise RuntimeError, "foo(double)"
if foo("hello") != "foo:char *":
raise RuntimeError, "foo(char *)"
f = Foo()
b = Bar()
if foo(f) != "foo:Foo *":
raise RuntimeError, "foo(Foo *)"
if foo(b) != "foo:Bar *":
raise RuntimeError, "foo(Bar *)"
v = malloc_void(32)
if foo(v) != "foo:void *":
raise RuntimeError, "foo(void *)"
s = Spam()
if s.foo(3) != "foo:int":
raise RuntimeError, "Spam::foo(int)"
if s.foo(3.0) != "foo:double":
raise RuntimeError, "Spam::foo(double)"
if s.foo("hello") != "foo:char *":
raise RuntimeError, "Spam::foo(char *)"
if s.foo(f) != "foo:Foo *":
raise RuntimeError, "Spam::foo(Foo *)"
if s.foo(b) != "foo:Bar *":
raise RuntimeError, "Spam::foo(Bar *)"
if s.foo(v) != "foo:void *":
raise RuntimeError, "Spam::foo(void *)"
if Spam_bar(3) != "bar:int":
raise RuntimeError, "Spam::bar(int)"
if Spam_bar(3.0) != "bar:double":
raise RuntimeError, "Spam::bar(double)"
if Spam_bar("hello") != "bar:char *":
raise RuntimeError, "Spam::bar(char *)"
if Spam_bar(f) != "bar:Foo *":
raise RuntimeError, "Spam::bar(Foo *)"
if Spam_bar(b) != "bar:Bar *":
raise RuntimeError, "Spam::bar(Bar *)"
if Spam_bar(v) != "bar:void *":
raise RuntimeError, "Spam::bar(void *)"
# Test constructors
s = Spam()
if s.type != "none":
raise RuntimeError, "Spam()"
s = Spam(3)
if s.type != "int":
raise RuntimeError, "Spam(int)"
s = Spam(3.4)
if s.type != "double":
raise RuntimeError, "Spam(double)"
s = Spam("hello")
if s.type != "char *":
raise RuntimeError, "Spam(char *)"
s = Spam(f)
if s.type != "Foo *":
raise RuntimeError, "Spam(Foo *)"
s = Spam(b)
if s.type != "Bar *":
raise RuntimeError, "Spam(Bar *)"
s = Spam(v)
if s.type != "void *":
raise RuntimeError, "Spam(void *)"
# unsigned long long
ullmax = 9223372036854775807 # 0xffffffffffffffff
ullmaxd = 9007199254740992.0
ullmin = 0
ullmind = 0.0
if ull(ullmin) != ullmin:
raise runtimeerror, "ull(ullmin)"
if ull(ullmax) != ullmax:
raise runtimeerror, "ull(ullmax)"
if ull(ullmind) != ullmind:
raise RuntimeError, "ull(ullmind)"
if ull(ullmaxd) != ullmaxd:
raise RuntimeError, "ull(ullmaxd)"
# long long
llmax = 9223372036854775807 # 0x7fffffffffffffff
llmin = -9223372036854775808
# these are near the largest floats we can still convert into long long
llmaxd = 9007199254740992.0
llmind = -9007199254740992.0
if ll(llmin) != llmin:
raise runtimeerror, "ll(llmin)"
if ll(llmax) != llmax:
raise runtimeerror, "ll(llmax)"
if ll(llmind) != llmind:
raise RuntimeError, "ll(llmind)"
if ll(llmaxd) != llmaxd:
raise RuntimeError, "ll(llmaxd)"
free_void(v)
|