Sha256: 9cd5cf5ffe631e9bc4d810f0a328c8fb248d0f4d384181415af49241e5e4eced

Contents?: true

Size: 1.65 KB

Versions: 9

Compression:

Stored size: 1.65 KB

Contents

require 'minitest/autorun'
require 'chartjs/axis_helpers'

class AxisHelpersTest < MiniTest::Unit::TestCase

  def setup
    @subject = Object.new
    @subject.extend Chartjs::AxisHelpers
  end

  def test_series_empty_data
    data = {}
    result = @subject.series data
    assert_equal 0, result.length
  end

  def test_series
    data = { 2 => 42 }
    result = @subject.series data
    assert_equal 3, result.length
    assert_equal({0 => 0, 1 => 0, 2 => 42}, result)
  end

  def test_calculate_scale_max
    {
         0 =>    0,
         3 =>    5,
         5 =>    5,
         6 =>   10,
         9 =>   10,
        10 =>   10,
        12 =>   15,
        16 =>   20,
        60 =>   60,
        65 =>   65,
       601 =>  650,
      1430 => 1500,
      7654 => 8000,
    }.each do |input, expected_output|
      assert_equal expected_output, @subject.calculate_scale_max(input)
    end
  end

  def test_ordinate_scale
    data = []
    assert_equal({scaleSteps: 0, scaleStepWidth: 0, scaleStartValue: 0}, @subject.ordinate_scale(data))

    data = [ 12 ]
    assert_equal({scaleSteps: 5, scaleStepWidth: 3, scaleStartValue: 0}, @subject.ordinate_scale(data))

    data = [ 33 ]
    assert_equal({scaleSteps: 7, scaleStepWidth: 5, scaleStartValue: 0}, @subject.ordinate_scale(data))

    data = [ 601 ]
    assert_equal({scaleSteps: 7, scaleStepWidth: 100, scaleStartValue: 0}, @subject.ordinate_scale(data))

    data = [ 999 ]
    assert_equal({scaleSteps: 5, scaleStepWidth: 200, scaleStartValue: 0}, @subject.ordinate_scale(data))

    data = [ 13001 ]
    assert_equal({scaleSteps: 5, scaleStepWidth: 3000, scaleStartValue: 0}, @subject.ordinate_scale(data))
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
chartjs-ror-2.2.0 test/axis_helpers_test.rb
chartjs-ror-2.1.3 test/axis_helpers_test.rb
chartjs-ror-2.1.2 test/axis_helpers_test.rb
chartjs-ror-2.1.1 test/axis_helpers_test.rb
chartjs-ror-2.1.0 test/axis_helpers_test.rb
chartjs-ror-2.0.0 test/axis_helpers_test.rb
chartjs-ror-1.1.1 test/axis_helpers_test.rb
chartjs-ror-1.1.0 test/axis_helpers_test.rb
chartjs-ror-1.0.1 test/axis_helpers_test.rb