diff --git a/LibGAP.jl/src/gap.jl b/LibGAP.jl/src/gap.jl index 773229aaa..c86b1b7b5 100644 --- a/LibGAP.jl/src/gap.jl +++ b/LibGAP.jl/src/gap.jl @@ -35,25 +35,29 @@ RNamObj(f::Symbol) = GAP.GAPFuncs.RNamObj(MakeString(string(f))) Base.getproperty(x::MPtr, f::Symbol) = GAP.GAPFuncs.ELM_REC(x, RNamObj(f)) Base.setproperty!(x::MPtr, f::Symbol, v) = GAP.GAPFuncs.ASS_REC(x, RNamObj(f), v) - -import Base: *, +, -, /, ^, mod, <, == - -typecombinations = [[:GAPInputType_noint,:GAPInputType_noint], - [:GAPInputType_noint,:Int64], - [:Int64,:GAPInputType_noint]] -function_combinations = [[:(+),:SUM], - [:(-),:DIFF], - [:(*),:PROD], - [:(/),:QUO], - [:(^),:POW], - [:(mod),:MOD], - [:(<),:LT], - [:(==),:EQ]] - -for types in typecombinations - for func in function_combinations +# +Base.zero(x::GAPInputType_noint) = GAP.GAPFuncs.ZERO(x) +Base.one(x::GAPInputType_noint) = GAP.GAPFuncs.ONE(x) +Base.:-(x::GAPInputType_noint) = GAP.GAPFuncs.AINV(x) + +# +typecombinations = ((:GAPInputType_noint,:GAPInputType_noint), + (:GAPInputType_noint,:Int64), + (:Int64,:GAPInputType_noint)) +function_combinations = ((:+,:SUM), + (:-,:DIFF), + (:*,:PROD), + (:/,:QUO), + (:\,:LQUO), + (:^,:POW), + (:mod,:MOD), + (:<,:LT), + (:(==),:EQ)) + +for (left, right) in typecombinations + for (funcJ, funcC) in function_combinations @eval begin - $(func[1])(x::$(types[1]),y::$(types[2])) = GAP.GAPFuncs.$(func[2])(x,y) + Base.$(funcJ)(x::$left,y::$right) = GAP.GAPFuncs.$(funcC)(x,y) end end end diff --git a/LibGAP.jl/test/convenience.jl b/LibGAP.jl/test/convenience.jl index 1f3b40bea..e3468e152 100644 --- a/LibGAP.jl/test/convenience.jl +++ b/LibGAP.jl/test/convenience.jl @@ -5,22 +5,31 @@ large_int = GAP.EvalString( "2^100;" )[1][2] large_int_p1 = GAP.EvalString( "2^100 + 1;" )[1][2] large_int_m1 = GAP.EvalString( "2^100 - 1;" )[1][2] - large_int_double = GAP.EvalString( "2^200;" )[1][2] + large_int_squared = GAP.EvalString( "2^200;" )[1][2] large_int_t2 = GAP.EvalString( "2^101;" )[1][2] + @test zero(large_int) == 0 + @test one(large_int) == 1 @test large_int + 1 == large_int_p1 @test 1 + large_int == large_int_p1 + @test large_int + (-large_int) == 0 + @test large_int - 1 == large_int_m1 @test large_int * 2 == large_int_t2 @test 2 * large_int == large_int_t2 - @test large_int * large_int == large_int_double + @test large_int * large_int == large_int_squared + @test large_int^2 == large_int_squared + @test large_int / large_int == 1 @test large_int / 2^50 == 2^50 + @test large_int \ large_int == 1 + @test 2^50 \ large_int == 2^50 + @test large_int < large_int_p1 @test large_int <= large_int_p1 @test large_int > large_int_m1 @@ -33,17 +42,21 @@ end @testset "ffe_arithmetics" begin - f3_gen = GAP.EvalString( "Z(3);" )[1][2] - f3_one = GAP.EvalString( "Z(3)^0;" )[1][2] - f3_zero = GAP.EvalString( "0 * Z(3);" )[1][2] + z3_gen = GAP.EvalString( "Z(3);" )[1][2] + z3_one = GAP.EvalString( "Z(3)^0;" )[1][2] + z3_zero = GAP.EvalString( "0 * Z(3);" )[1][2] + + z3 = GAP.GAPFuncs.Z(3) - f3_call = GAP.GAPFuncs.Z(3) + @test z3_gen == z3 + @test z3_one == one(z3) + @test z3_zero == zero(z3) - @test f3_call * 1 == f3_gen - @test f3_call + 1 == f3_zero - @test f3_call + 2 == f3_one - @test f3_call ^ 2 == f3_one - @test f3_call - 1 == f3_one + @test z3 * 1 == z3_gen + @test z3 + 1 == z3_zero + @test z3 + 2 == z3_one + @test z3 ^ 2 == z3_one + @test z3 - 1 == z3_one end @testset "object_access" begin