| 1 |
require "test_helper" |
| 2 |
require "matrix" |
| 3 |
|
| 4 |
class TestRooFormatterMatrix < Minitest::Test |
| 5 |
def test_matrix |
| 6 |
expected_result = Matrix[ |
| 7 |
[1.0, 2.0, 3.0], |
| 8 |
[4.0, 5.0, 6.0], |
| 9 |
[7.0, 8.0, 9.0] |
| 10 |
] |
| 11 |
with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook| |
| 12 |
workbook.default_sheet = workbook.sheets.first |
| 13 |
assert_equal expected_result, workbook.to_matrix |
| 14 |
end |
| 15 |
end |
| 16 |
|
| 17 |
def test_matrix_selected_range |
| 18 |
expected_result = Matrix[ |
| 19 |
[1.0, 2.0, 3.0], |
| 20 |
[4.0, 5.0, 6.0], |
| 21 |
[7.0, 8.0, 9.0] |
| 22 |
] |
| 23 |
with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook| |
| 24 |
workbook.default_sheet = "Sheet2" |
| 25 |
assert_equal expected_result, workbook.to_matrix(3, 4, 5, 6) |
| 26 |
end |
| 27 |
end |
| 28 |
|
| 29 |
def test_matrix_all_nil |
| 30 |
expected_result = Matrix[ |
| 31 |
[nil, nil, nil], |
| 32 |
[nil, nil, nil], |
| 33 |
[nil, nil, nil] |
| 34 |
] |
| 35 |
with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook| |
| 36 |
workbook.default_sheet = "Sheet2" |
| 37 |
assert_equal expected_result, workbook.to_matrix(10, 10, 12, 12) |
| 38 |
end |
| 39 |
end |
| 40 |
|
| 41 |
def test_matrix_values_and_nil |
| 42 |
expected_result = Matrix[ |
| 43 |
[1.0, nil, 3.0], |
| 44 |
[4.0, 5.0, 6.0], |
| 45 |
[7.0, 8.0, nil] |
| 46 |
] |
| 47 |
with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook| |
| 48 |
workbook.default_sheet = "Sheet3" |
| 49 |
assert_equal expected_result, workbook.to_matrix(1, 1, 3, 3) |
| 50 |
end |
| 51 |
end |
| 52 |
|
| 53 |
def test_matrix_specifying_sheet |
| 54 |
expected_result = Matrix[ |
| 55 |
[1.0, nil, 3.0], |
| 56 |
[4.0, 5.0, 6.0], |
| 57 |
[7.0, 8.0, nil] |
| 58 |
] |
| 59 |
with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook| |
| 60 |
workbook.default_sheet = workbook.sheets.first |
| 61 |
assert_equal expected_result, workbook.to_matrix(nil, nil, nil, nil, "Sheet3") |
| 62 |
end |
| 63 |
end |
| 64 |
|
| 65 |
# #to_matrix of an empty sheet should return an empty matrix and not result in |
| 66 |
# an error message |
| 67 |
# 2011-06-25 |
| 68 |
def test_bug_to_matrix_empty_sheet |
| 69 |
options = { name: "emptysheets", format: [:openoffice, :excelx] } |
| 70 |
with_each_spreadsheet(options) do |workbook| |
| 71 |
workbook.default_sheet = workbook.sheets.first |
| 72 |
workbook.to_matrix |
| 73 |
assert_equal(Matrix.empty(0, 0), workbook.to_matrix) |
| 74 |
end |
| 75 |
end |
| 76 |
end |