From 4be3bbf5e8d53631efd28cacfbd3e23b86df55d4 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Wed, 2 Jan 2019 16:13:41 +0100 Subject: [PATCH] better printing --- src/GroupRings.jl | 17 +++++++++++++---- test/runtests.jl | 8 ++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index 92f9eee..864c743 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -224,15 +224,24 @@ end function show(io::IO, X::GroupRingElem) RG = parent(X) + T = eltype(X.coeffs) if X.coeffs == zero(X.coeffs) - T = eltype(X.coeffs) print(io, "$(zero(T))*$((RG.group)())") elseif isdefined(RG, :basis) non_zeros = ((X.coeffs[i], RG.basis[i]) for i in findall(!iszero, X.coeffs)) - elts = ("$(sign(c)> 0 ? " + " : " - ")$(abs(c))*$g" for (c,g) in non_zeros) - str = join(elts, "")[2:end] + elts = String[] + for (c,g) in non_zeros + sgn = (sign(c)>=0 ? " + " : " - ") + if c == T(1) + coeff = "" + else + coeff = "$(abs(c))" + end + push!(elts, sgn*coeff*"$(g)") + end + str = join(elts, "") if sign(first(non_zeros)[1]) > 0 - str = str[3:end] + str = str[4:end] end print(io, str) else diff --git a/test/runtests.jl b/test/runtests.jl index 2d682fa..bd0878c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -98,8 +98,8 @@ using SparseArrays @test a[5] == 1 @test a[p] == 1 - @test string(a) == "1*(1,2,3)" - @test string(-a) == "- 1*(1,2,3)" + @test string(a) == "(1,2,3)" + @test string(-a) == " - 1(1,2,3)" @test RG([0,0,0,0,1,0]) == a @@ -111,8 +111,8 @@ using SparseArrays @test a[1] == 2 @test a[s] == 2 - @test string(a) == "2*() + 1*(1,2,3)" - @test string(-a) == "- 2*() - 1*(1,2,3)" + @test string(a) == "2() + (1,2,3)" + @test string(-a) == " - 2() - 1(1,2,3)" @test length(a) == 2 end