diff --git a/src/roots.jl b/src/roots.jl index d1fdb3d..92a915c 100644 --- a/src/roots.jl +++ b/src/roots.jl @@ -5,7 +5,7 @@ using LinearAlgebra export Root, isproportional, isorthogonal, ~, ⟂ -abstract type AbstractRoot{N,T} end +abstract type AbstractRoot{N,T} end # <: AbstractVector{T} ? ℓ₂length(r::AbstractRoot) = norm(r, 2) ambient_dim(r::AbstractRoot) = length(r) @@ -37,8 +37,8 @@ end function Base.show(io::IO, ::MIME"text/plain", r::AbstractRoot) l₂l = ℓ₂length(r) - l = isinteger(l₂l) ? "$(l₂l)" : "√$(l₂l^2)" - return print(io, "Root in ℝ^$N of length $l\n", r.coord) + l = round(Int, l₂l) ≈ l₂l ? "$(round(Int, l₂l))" : "√$(round(Int, l₂l^2))" + return print(io, "Root in ℝ^$(length(r)) of length $l\n", r.coord) end function reflection(α::AbstractRoot, β::AbstractRoot) diff --git a/test/roots.jl b/test/roots.jl new file mode 100644 index 0000000..7cb32d0 --- /dev/null +++ b/test/roots.jl @@ -0,0 +1,10 @@ +using PropertyT.Roots +@testset "Roots" begin + @test Roots.Root{3,Int}([1, 2, 3]) isa Roots.AbstractRoot{} + @test Roots.Root([1, 2, 3]) isa Roots.AbstractRoot{3,Int} + # io + r = Roots.Root{3,Int}([1, 2, 3]) + @test contains(sprint(show, MIME"text/plain"(), r), "of length √14\n") + r = Roots.Root{3,Int}([1, 2, 2]) + @test contains(sprint(show, MIME"text/plain"(), r), "of length 3\n") +end diff --git a/test/runtests.jl b/test/runtests.jl index 5e6a9be..a306e55 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -24,6 +24,7 @@ if haskey(ENV, "FULL_TEST") || haskey(ENV, "CI") include("1712.07167.jl") include("1812.03456.jl") + include("roots.jl") include("graded_adj.jl") include("Chevalley.jl") end