Sha256: e6f6127a96f5f00f7d2cdd275ebecea664575e231c89e868144a10857bd913cb

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

require "test_helper"

class Mathematical::MultiplesTest < Test::Unit::TestCase

  def setup
    @render = Mathematical.new(:base64 => true)
  end

  def test_it_works_for_a_single_numbered_equation
    string = '''
$$
\begin{equation}
 f(x)=(x+a)(x+b)
\end{equation}
$$
'''

    output = @render.render([string])
    svg = output.first[:data]

    assert_equal 1, svg.scan(/svg\+xml;/).size, 'should only contain one svg'
    assert_match 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My', svg
  end

  def test_it_works_for_many_equations
    inputs = []
    (1..1000).each do |i|
      string = """
  $$
  \\begin{equation}
   f(#{i})=(x+a)(x+b)
  \\end{equation}
  $$
  """
      inputs << string
    end

    output = @render.render(inputs)
    assert_equal 1000, output.length
    output.each do |data|
      assert_match 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My', data[:data]
    end
  end

  def test_it_properly_accounts_for_equations
    inputs = []
    (1..2).each do |i|
      string = """
  $$
  \\begin{equation}
   f(#{i})=(x+a)(x+b)
  \\end{equation}
  $$
  """
      inputs << string
    end

    inputs.insert(1, '$test$')
    render = Mathematical.new({:format => :png})
    output = render.render(inputs)
    assert_equal 3, output.length
    output.each_with_index do |data_hash, i|
      header = data_hash[:data].unpack('H*').first.slice(0, 18)
      File.open("#{fixtures_dir}/png/numeric_test_#{i + 1}.png", 'w') { |f| f.write(data_hash[:data])}
      assert_equal header, '89504e470d0a1a0a00'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mathematical-1.1.1 test/mathematical/multiples_test.rb
mathematical-1.1.0 test/mathematical/multiples_test.rb