Skip to content

Commit e6a459e

Browse files
committed
Reject spy matrices with rows and zero columns
1 parent b16fd21 commit e6a459e

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎spec/audit_numeric_spec.cr‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ describe "audited numeric and matrix behavior" do
9393
lower_io.to_s.should_not contain("[48;")
9494
end
9595

96+
it "rejects spy matrices with rows but zero columns" do
97+
[1, 2].each do |nrows|
98+
rows = Array(Array(Float64)).new(nrows) { [] of Float64 }
99+
expect_raises(ArgumentError, /zero columns/) do
100+
UnicodePlot.spy(rows, height: 2, width: 2)
101+
end
102+
end
103+
end
104+
96105
it "stops contours at missing cells without erasing small coordinates" do
97106
missing = UnicodePlot::MatrixView.new([[0.0, 0.0, Float64::NAN], [1.0, 1.0, 2.0]])
98107
level = UnicodePlot::Contour.contour([0.0, 1.0, 2.0], [0.0, 1.0], missing, 0.5)

‎src/unicode_plot/interface/spy.cr‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ module UnicodePlot
117117

118118
nrows = matrix.nrows
119119
ncols = matrix.ncols
120+
# A nonempty matrix with zero columns has no drawable width or aspect ratio.
121+
# Keep the supported 0x0 case, but report this shape before sizing it.
122+
raise ArgumentError.new("spy cannot draw rows with zero columns") if nrows > 0 && ncols == 0
123+
120124
row_coords = matrix_row_coords(matrix)
121125
col_coords = matrix_col_coords(matrix)
122126

0 commit comments

Comments
 (0)