Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix redundant newline in show for IncidenceMatrix #505

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/incidencematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

function IncidenceMatrix{NonSymmetric}(mat::AbstractMatrix)
res = IncidenceMatrix{NonSymmetric}(undef, size(mat)...)
if eltype(mat) != Bool && any(x->!isone(x) && !iszero(x), mat)
throw(ArgumentError("matrix entries must be 0 or 1"))

Check warning on line 15 in src/incidencematrix.jl

View check run for this annotation

Codecov / codecov/patch

src/incidencematrix.jl#L15

Added line #L15 was not covered by tests
end
@inbounds res .= mat
return res
end
Expand Down Expand Up @@ -143,18 +146,19 @@
function Base.show(io::IOContext, ::MIME{Symbol("text/plain")}, M::IncidenceMatrix)
m,n = size(M)
a,b = displaysize(io)
s = min(a - 5, size(M, 1))
print(io, "$m×$n IncidenceMatrix\n")
s = min(a - 5, m)
print(io, "$m×$n IncidenceMatrix")
for i in 1:s
t = min(div(b, 2 + ndigits(size(M, 2))) - 1, length(row(M, i)))
print(io, "[")
println(io)
t = min(div(b, 2 + ndigits(n)) - 1, length(row(M, i)))
print(io, " [")
join(io, [c for c in row(M, i)][1:t], ", ")
if (length(row(M,i)) > t)
print(io, ", …")
end
print(io, "]\n")
print(io, "]")
end
if (m > s)
print(io, "⁝")
print(io, "\n ⁝")

Check warning on line 162 in src/incidencematrix.jl

View check run for this annotation

Codecov / codecov/patch

src/incidencematrix.jl#L162

Added line #L162 was not covered by tests
end
end
4 changes: 2 additions & 2 deletions test/incidencematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ using Polymake.SparseArrays
@test N[2, 2] = T(10) isa T
N[2, 2] = T(10)
@test N[2, 2] == true
@test string(N) == "2×3 IncidenceMatrix\n[1, 3]\n[1, 2]\n"
@test string(N) == "2×3 IncidenceMatrix\n [1, 3]\n [1, 2]"
# testing the return value when asking for a single row or column
@test Polymake.row(N, T(1)) isa Polymake.Set{Polymake.to_cxx_type(Int)}
@test Polymake.row(N, T(1)) == Set([1, 3])
Expand Down Expand Up @@ -151,7 +151,7 @@ using Polymake.SparseArrays
S[1, 3] = T(0)
@test S[1, 3] == false
@test S[3, 1] == false
@test string(S) == "3×3 IncidenceMatrix\n[1]\n[]\n[3]\n"
@test string(S) == "3×3 IncidenceMatrix\n [1]\n []\n [3]"
# testing the return value when asking for a single row or column
@test Polymake.row(S, T(2)) isa Polymake.Set{Polymake.to_cxx_type(Int)}
@test Polymake.row(S, T(2)) == Set([])
Expand Down
Loading