runtests.jl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using SyntaxTree, Reduce
  2. using Test
  3. @force using Reduce.Algebra
  4. # write your own tests here
  5. @test showerror(stdout,ReduceError("A Portable General-Purpose Computer Algebra System")) == nothing
  6. @test rcall(:((1+pi)^2)) == convert(Expr,RExpr(rcall("(1+pi)**2")))
  7. @test try; "1/0" |> rcall; false; catch; true; end
  8. @test Reduce.Reset() == nothing
  9. @test display(RExpr("(x+i)^3")) == nothing; print('\n')
  10. @test Reduce._syme(Reduce.r_to_jl) |> typeof == String
  11. @test R"x+2" == R"2+x-1+1"
  12. @test :((x+1+π)^2; int(1/(1+x^3),x)) |> RExpr |> Reduce.parse |> typeof == Expr
  13. @test !Base.process_exited(Reduce.rs)
  14. @test string(R"x+1") |> typeof == String
  15. @test RExpr(:x) == R"x"
  16. @test RExpr(:x)*R"x" == R"x^2"
  17. @test convert(RExpr,R"x").str == convert(Array{String,1},R"x")
  18. @test load_package([:rlfi]) == load_package(:rlfi,:rlfi)
  19. @test show(stdout, R"") == nothing
  20. @test show(stdout,"text/latex",R"int(sinh(e**i*z),z)") == nothing
  21. @test Base.write(Reduce.rs, R"") |> typeof == Int; rcall(1)
  22. @test (x = :(x^2+2x+1); rcall(x,off=[:factor]) == x)
  23. @test rcall("x + 1","factor") == "x + 1"
  24. @test Expr(:function,:fun,:(return begin; x = 700; y = x; end)) |> RExpr |> Reduce.parse |> typeof == Expr
  25. @test Expr(:for,:(i=2:34),:(product(i))) |> rcall |> eval |> typeof == BigInt
  26. @test try; Expr(:type,false,:x) |> RExpr; false; catch; true; end
  27. @test try; :(@time f(x)) |> RExpr; false; catch; true; end
  28. @test (x = Expr(:function,:fun,:(return y=a^3+3*a^2*b+3*a*b^2+b^3)); x==x |> Reduce.factor |> expand)
  29. @test try; Expr(:for,:(i=2:34),:(product(i))) |> RExpr |> Reduce.parse; false; catch; true; end
  30. @test R"begin; 1:2; end" |> Reduce.parse |> RExpr |> string == "1:2 "
  31. @test latex(:(x+1)) |> typeof == String
  32. @test length(:(x+y)) |> typeof == Int
  33. @test log(:(ℯ^x)) == :x
  34. @test nextprime(100) == 101
  35. @test ceiling(1.2) == 2
  36. @test impart(:(1+2*im)) == 2
  37. @test impart(2+1.7im) == 17/10
  38. @test bernoulli(2) == 1/6
  39. @test Reduce.parsegen(:parsetest,:expr) |> typeof == Expr
  40. @test Reduce.parsegen(:calctest,:args) |> typeof == Expr
  41. @test Reduce.parsegen(:switchtest,:switch) |> typeof == Expr
  42. @test Reduce.parsegen(:unarytest,:unary) |> typeof == Expr
  43. Sys.islinux() && @test Reduce.RSymReplace("!#03a9; *x**2 + !#03a9;") |> typeof == String
  44. @test :((x+im+π)^2; int(1/(1+x^3),x)) |> RExpr |> rcall |> Reduce.parse |> typeof == Expr
  45. @test :(int(sin(im*x+pi)^2-1,x)) |> rcall |> typeof == Expr
  46. @test int(:(x^2+y),:x) |> RExpr == int("x^2+y","x") |> RExpr
  47. @test R"/(2,begin 2; +(7,4); return +(4,*(2,7))+9 end)" |> Reduce.parse |> typeof == Expr
  48. @test df(Expr(:function,:fun,:(return begin; zn = z^2+c; nz = z^3-1; end))|>RExpr,:z) |> typeof == RExpr
  49. @test :([1 2; 3 4]) |> RExpr |> Reduce.parse |> RExpr == [1 2; 3 4] |> RExpr
  50. println()
  51. #@test Reduce.repl_init(Base.active_repl)==nothing
  52. @test nextprime("3") == "5"
  53. @test expand("(x-2)^2") |> RExpr == R"(x-2)^2"
  54. @test nat("x+1") |> RExpr == "\nx + 1\n" |> RExpr
  55. @test macroexpand(@__MODULE__(),@factor(:(x^2+2x+1))) == :((x+1)^2)
  56. @test :x^2 == :(x^2)
  57. @test NaN//NaN |> isnan
  58. @test join(split(R"x+1;x+2"))|> string == "x+1;\nx+2"
  59. @test sub(:x=>7,:x+7) == sub([:x=>7,:z=>21],:z-:x)
  60. @test SyntaxTree.sub(Float64,prod((:x-:n)^:n,:n,1,7)|>horner) |> typeof == Expr
  61. @test squash(Expr(:function,:(fun(x)),:(z=3;z+=:x))).args[2] == squash(:(y=:x;y+=3))
  62. @test squash(:(sqrt(x)^2)) == :x
  63. @test Expr(:block,:(x+1)) |> RExpr == R"1+x"
  64. @test limit((1-1/:n)^-:n,:n,Inf) == ℯ
  65. @test log(exp(:pi)) == π
  66. @test 2//Inf == 0
  67. @test Inf//2 == Inf
  68. @test (rcall("x"); Algebra.ws() == :x)
  69. @test (operator(:x); operator(:x); clear(:x); true)
  70. @test try det([:x :y]) catch; true end
  71. @test join([R"1",R"1"]) == R"1;1"
  72. @test list([R"1",R"x"]) == list((1,:x))
  73. @test Reduce.lister(:x) == R"x"
  74. @test !latex(false)
  75. @test (@rounded @factor x^2-2x+1) == :((x-1)^2)
  76. @test (@rounded @off_factor @rcall x^2) == :(x^2)
  77. @test det([:a :b; :c :d]) == :(a*d-b*c)
  78. @test tp([:a;:b]) == [:a :b;]
  79. @test transpose(:x) == :x
  80. @test adjoint(:x) == :(repart(x)-impart(x)*im)
  81. operator(:cbrt)
  82. @test (rlet(:(cbrt(~x))=>:(x^(1/3))); true)
  83. @test (rlet([:(cbrt(~x))=>:(x^(1/3))]); true)
  84. @test (rlet(Dict(:(cbrt(~x))=>:(x^(1/3)))); true)
  85. @test 1+R"x" == :(x+1)
  86. @test inv([:a :b; :c :d]) |> typeof <: Array
  87. @test inv(1) == 1.0
  88. @test [1 2; 3 4]\[1,2] == [0.0,0.5]
  89. @test 1.0//1.0 == 1
  90. @test [:a :b; :c :d]/2 |> typeof <: Array
  91. @test [:a :b; :c :d]+1 == 1+[:a :b; :c :d]
  92. @test [:x] + 1 == 1 + [:x]
  93. @test [:x,:y]' + 1 == 1 + [:x,:y]'
  94. @test solve(:(x-1),:x) == solve((:(x-1),),:x)
  95. @test (order(nothing); korder(nothing); true)
  96. @test (Reduce.@subtype FakeReal <: Real; FakeReal(:(x+1)) + FakeReal(:y) == FakeReal(:(x+1+y)))