|
208 | 208 | @test !pyin(pybuiltins.None, x) |
209 | 209 | end |
210 | 210 | end |
| 211 | + |
| 212 | +@testset "iter" begin |
| 213 | + @test_throws PyException pyiter(pybuiltins.None) |
| 214 | + @test_throws PyException pyiter(pybuiltins.True) |
| 215 | + it = pyiter(pyrange(2)) |
| 216 | + x = PythonCall.pynext(it) |
| 217 | + @test !PythonCall.ispynull(x) |
| 218 | + @test pyeq(Bool, x, 0) |
| 219 | + x = PythonCall.pynext(it) |
| 220 | + @test !PythonCall.ispynull(x) |
| 221 | + @test pyeq(Bool, x, 1) |
| 222 | + x = PythonCall.pynext(it) |
| 223 | + @test PythonCall.ispynull(x) |
| 224 | +end |
| 225 | + |
| 226 | +@testset "number" begin |
| 227 | + @testset "pyneg" begin |
| 228 | + for n in -2:2 |
| 229 | + @test pyeq(Bool, pyneg(pyint(n)), pyint(-n)) |
| 230 | + end |
| 231 | + end |
| 232 | + @testset "pypos" begin |
| 233 | + for n in -2:2 |
| 234 | + @test pyeq(Bool, pypos(pyint(n)), pyint(n)) |
| 235 | + end |
| 236 | + end |
| 237 | + @testset "pyabs" begin |
| 238 | + for n in -2:2 |
| 239 | + @test pyeq(Bool, pyabs(pyint(n)), pyint(abs(n))) |
| 240 | + end |
| 241 | + end |
| 242 | + @testset "pyinv" begin |
| 243 | + for n in -2:2 |
| 244 | + @test pyeq(Bool, pyinv(pyint(n)), pyint(-n-1)) |
| 245 | + end |
| 246 | + end |
| 247 | + @testset "pyindex" begin |
| 248 | + for n in -2:2 |
| 249 | + @test pyeq(Bool, pyindex(pyint(n)), pyint(n)) |
| 250 | + end |
| 251 | + end |
| 252 | + @testset "pyadd" begin |
| 253 | + for x in -2:2 |
| 254 | + for y in -2:2 |
| 255 | + @test pyeq(Bool, pyadd(pyint(x), pyint(y)), pyint(x+y)) |
| 256 | + end |
| 257 | + end |
| 258 | + end |
| 259 | + @testset "pysub" begin |
| 260 | + for x in -2:2 |
| 261 | + for y in -2:2 |
| 262 | + @test pyeq(Bool, pysub(pyint(x), pyint(y)), pyint(x-y)) |
| 263 | + end |
| 264 | + end |
| 265 | + end |
| 266 | + @testset "pymul" begin |
| 267 | + for x in -2:2 |
| 268 | + for y in -2:2 |
| 269 | + @test pyeq(Bool, pymul(pyint(x), pyint(y)), pyint(x*y)) |
| 270 | + end |
| 271 | + end |
| 272 | + end |
| 273 | + # TODO |
| 274 | + # @testset "pymatmul" begin |
| 275 | + # for x in -2:2 |
| 276 | + # for y in -2:2 |
| 277 | + # @test pyeq(Bool, pymul(pyint(x), pyint(y)), pyint(x*y)) |
| 278 | + # end |
| 279 | + # end |
| 280 | + # end |
| 281 | + @testset "pytruediv" begin |
| 282 | + for x in -2:2 |
| 283 | + for y in -2:2 |
| 284 | + if y == 0 |
| 285 | + @test_throws PyException pytruediv(pyint(x), pyint(y)) |
| 286 | + else |
| 287 | + @test pyeq(Bool, pytruediv(pyint(x), pyint(y)), pyfloat(x/y)) |
| 288 | + end |
| 289 | + end |
| 290 | + end |
| 291 | + end |
| 292 | + @testset "pyfloordiv" begin |
| 293 | + for x in -2:2 |
| 294 | + for y in -2:2 |
| 295 | + if y == 0 |
| 296 | + @test_throws PyException pyfloordiv(pyint(x), pyint(y)) |
| 297 | + else |
| 298 | + @test pyeq(Bool, pyfloordiv(pyint(x), pyint(y)), pyfloat(fld(x, y))) |
| 299 | + end |
| 300 | + end |
| 301 | + end |
| 302 | + end |
| 303 | + @testset "pymod" begin |
| 304 | + for x in -2:2 |
| 305 | + for y in -2:2 |
| 306 | + if y == 0 |
| 307 | + @test_throws PyException pymod(pyint(x), pyint(y)) |
| 308 | + else |
| 309 | + @test pyeq(Bool, pymod(pyint(x), pyint(y)), pyint(mod(x, y))) |
| 310 | + end |
| 311 | + end |
| 312 | + end |
| 313 | + end |
| 314 | + @testset "pydivmod" begin |
| 315 | + for x in -2:2 |
| 316 | + for y in -2:2 |
| 317 | + if y == 0 |
| 318 | + @test_throws PyException pydivmod(pyint(x), pyint(y)) |
| 319 | + else |
| 320 | + @test pyeq(Bool, pydivmod(pyint(x), pyint(y)), pytuple(fldmod(x, y))) |
| 321 | + end |
| 322 | + end |
| 323 | + end |
| 324 | + end |
| 325 | + @testset "pylshift" begin |
| 326 | + for n in 0:3 |
| 327 | + @test pyeq(Bool, pylshift(pyint(123), pyint(n)), pyint(123 << n)) |
| 328 | + end |
| 329 | + end |
| 330 | + @testset "pyrshift" begin |
| 331 | + for n in 0:3 |
| 332 | + @test pyeq(Bool, pyrshift(pyint(123), pyint(n)), pyint(123 >> n)) |
| 333 | + end |
| 334 | + end |
| 335 | + @testset "pyand" begin |
| 336 | + for x in 0:3 |
| 337 | + for y in 0:3 |
| 338 | + @test pyeq(Bool, pyand(pyint(x), pyint(y)), pyint(x & y)) |
| 339 | + end |
| 340 | + end |
| 341 | + end |
| 342 | + @testset "pyxor" begin |
| 343 | + for x in 0:3 |
| 344 | + for y in 0:3 |
| 345 | + @test pyeq(Bool, pyxor(pyint(x), pyint(y)), pyint(x ⊻ y)) |
| 346 | + end |
| 347 | + end |
| 348 | + end |
| 349 | + @testset "pyor" begin |
| 350 | + for x in 0:3 |
| 351 | + for y in 0:3 |
| 352 | + @test pyeq(Bool, pyor(pyint(x), pyint(y)), pyint(x | y)) |
| 353 | + end |
| 354 | + end |
| 355 | + end |
| 356 | + # TODO: in-place operators |
| 357 | +end |
0 commit comments