Skip to content

Commit bedb3b2

Browse files
author
Christopher Doris
committed
unit tests for julianumber
1 parent 65e2a79 commit bedb3b2

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

test/runtests.jl

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ end
1212

1313
@testset "eval" begin
1414
@pyg ```
15-
import sys, os, datetime, array, io, fractions, array, ctypes
15+
import sys, os, datetime, array, io, fractions, array, ctypes, numbers, math
1616
eq = lambda a, b: type(a) is type(b) and a == b
1717
class Foo:
1818
def __init__(self, x=None):
@@ -872,6 +872,46 @@ end
872872
@test @pyv `$(pyjl(identity)).__name__ == "identity"`::Bool
873873
end
874874

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+
875915
@testset "juliaio" begin
876916
for value in Any[stdin, stdout, IOBuffer()]
877917
@test @pyv `type($(pyjl(value))).__name__ == "BufferedIOValue"`::Bool

0 commit comments

Comments
 (0)