|
12 | 12 |
|
13 | 13 | @testset "eval" begin |
14 | 14 | @pyg ``` |
15 | | - import sys, os, datetime, array, io, fractions, array, ctypes |
| 15 | + import sys, os, datetime, array, io, fractions, array, ctypes, numbers, math |
16 | 16 | eq = lambda a, b: type(a) is type(b) and a == b |
17 | 17 | class Foo: |
18 | 18 | def __init__(self, x=None): |
|
872 | 872 | @test @pyv `$(pyjl(identity)).__name__ == "identity"`::Bool |
873 | 873 | end |
874 | 874 |
|
| 875 | + @testset "julianumber" begin |
| 876 | + xi = pyjl(1) |
| 877 | + xq = pyjl(1//2) |
| 878 | + xf = pyjl(0.4) |
| 879 | + xc = pyjl(1+2im) |
| 880 | + @test @pyv `isinstance($xi, numbers.Integral)`::Bool |
| 881 | + @test @pyv `isinstance($xq, numbers.Rational)`::Bool |
| 882 | + @test @pyv `isinstance($xf, numbers.Real)`::Bool |
| 883 | + @test @pyv `isinstance($xc, numbers.Complex)`::Bool |
| 884 | + @test @pyv `bool($xi)`::Bool |
| 885 | + @test @pyv `not bool($(pyjl(0.0)))`::Bool |
| 886 | + @test @pyv `+$xi == $xi`::Bool |
| 887 | + @test @pyv `-$xi == $(pyjl(-1))`::Bool |
| 888 | + @test @pyv `abs($(pyjl(-3.0))) == $(pyjl(3.0))`::Bool |
| 889 | + @test @pyv `$xi + $xq == $(pyjl(3//2))`::Bool |
| 890 | + @test @pyv `$(pyjl(0.5))**2 == $(pyjl(0.25))`::Bool |
| 891 | + @test @pyv `pow($(pyjl(2)),$(pyjl(5)),$(pyjl(10))) == $(pyjl(2))`::Bool |
| 892 | + @test @pyv `$xc.real == $(pyjl(1))`::Bool |
| 893 | + @test @pyv `$xc.imag == $(pyjl(2))`::Bool |
| 894 | + @test @pyv `$xc.conjugate() == $(pyjl(Complex(1-2im)))`::Bool |
| 895 | + @test @pyv `complex($xc) == complex(1,2)`::Bool |
| 896 | + @test @pyv `$xq.real == $xq`::Bool |
| 897 | + @test @pyv `$xq.imag == $(pyjl(0))`::Bool |
| 898 | + @test @pyv `$xq.conjugate() == $xq`::Bool |
| 899 | + @test @pyv `complex($xq) == complex(0.5)`::Bool |
| 900 | + @test @pyv `float($xq) == 0.5`::Bool |
| 901 | + @test @pyv `math.trunc($xq) == 0`::Bool |
| 902 | + @test @pyv `math.floor($xq) == 0`::Bool |
| 903 | + @test @pyv `math.ceil($xq) == 1`::Bool |
| 904 | + @test @pyv `round($xq) == 0`::Bool |
| 905 | + @test @pyv `round($xq, 1) == 0.5`::Bool |
| 906 | + @test @pyv `$xq.numerator == $(pyjl(1))`::Bool |
| 907 | + @test @pyv `$xq.denominator == $(pyjl(2))`::Bool |
| 908 | + @test @pyv `$xi.numerator == $(pyjl(1))`::Bool |
| 909 | + @test @pyv `$xi.denominator == 1`::Bool |
| 910 | + @test @pyv `int($xi) == 1`::Bool |
| 911 | + @test @pyv `$xi.__index__() == 1`::Bool |
| 912 | + @test @pyv `~$xi == $(pyjl(-2))`::Bool |
| 913 | + end |
| 914 | + |
875 | 915 | @testset "juliaio" begin |
876 | 916 | for value in Any[stdin, stdout, IOBuffer()] |
877 | 917 | @test @pyv `type($(pyjl(value))).__name__ == "BufferedIOValue"`::Bool |
|
0 commit comments