diff options
| author | David N. Robinson <[email protected]> | 2017-11-07 16:51:30 +0200 |
|---|---|---|
| committer | David N. Robinson <[email protected]> | 2017-11-17 06:14:33 +0200 |
| commit | ef396a558b35644c79b74e009acb44b52db36ed1 (patch) | |
| tree | ebbaa0f951b9d99fae372bc319fbacdfc5b7cbe2 /test/drawing/tc_bar_chart.rb | |
| parent | e855b75cd13e5a7e16c755ab648594c5a85e6653 (diff) | |
| download | caxlsx-ef396a558b35644c79b74e009acb44b52db36ed1.tar.gz caxlsx-ef396a558b35644c79b74e009acb44b52db36ed1.zip | |
Add support for non-3D bar charts
Diffstat (limited to 'test/drawing/tc_bar_chart.rb')
| -rw-r--r-- | test/drawing/tc_bar_chart.rb | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test/drawing/tc_bar_chart.rb b/test/drawing/tc_bar_chart.rb new file mode 100644 index 00000000..ca1ca016 --- /dev/null +++ b/test/drawing/tc_bar_chart.rb @@ -0,0 +1,71 @@ +require 'tc_helper.rb' + +class TestBarChart < Test::Unit::TestCase + + def setup + @p = Axlsx::Package.new + ws = @p.workbook.add_worksheet + @row = ws.add_row ["one", 1, Time.now] + @chart = ws.add_chart Axlsx::BarChart, :title => "fishery" + end + + def teardown + end + + def test_initialization + assert_equal(@chart.grouping, :clustered, "grouping defualt incorrect") + assert_equal(@chart.series_type, Axlsx::BarSeries, "series type incorrect") + assert_equal(@chart.bar_dir, :bar, " bar direction incorrect") + assert(@chart.cat_axis.is_a?(Axlsx::CatAxis), "category axis not created") + assert(@chart.val_axis.is_a?(Axlsx::ValAxis), "value access not created") + end + + def test_bar_direction + assert_raise(ArgumentError, "require valid bar direction") { @chart.bar_dir = :left } + assert_nothing_raised("allow valid bar direction") { @chart.bar_dir = :col } + assert(@chart.bar_dir == :col) + end + + def test_grouping + assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted } + assert_nothing_raised("allow valid grouping") { @chart.grouping = :standard } + assert(@chart.grouping == :standard) + end + + + def test_gapWidth + assert_raise(ArgumentError, "require valid gap width") { @chart.gap_width = 200 } + assert_nothing_raised("allow valid gapWidth") { @chart.gap_width = "200%" } + assert(@chart.gap_width == "200%") + end + + def test_gapDepth + assert_raise(ArgumentError, "require valid gap_depth") { @chart.gap_depth = 200 } + assert_nothing_raised("allow valid gap_depth") { @chart.gap_depth = "200%" } + assert(@chart.gap_depth == "200%") + end + + def test_shape + assert_raise(ArgumentError, "require valid shape") { @chart.shape = :star } + assert_nothing_raised("allow valid shape") { @chart.shape = :cone } + assert(@chart.shape == :cone) + end + + def test_to_xml_string + schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD)) + doc = Nokogiri::XML(@chart.to_xml_string) + errors = [] + schema.validate(doc).each do |error| + errors.push error + puts error.message + end + assert(errors.empty?, "error free validation") + end + + def test_to_xml_string_has_axes_in_correct_order + str = @chart.to_xml_string + cat_axis_position = str.index(@chart.axes[:cat_axis].id.to_s) + val_axis_position = str.index(@chart.axes[:val_axis].id.to_s) + assert(cat_axis_position < val_axis_position, "cat_axis must occur earlier than val_axis in the XML") + end +end |
