<commit_before>require 'test_helper'

class TestLatexEval < MiniTest::Unit::TestCase
  def test_parse_nesting
    assert_equal (:x.l + (:y.l + (:z.l - 3.l))).latex,
    parse_unparse('x+\left(y+\left(z-3\right)\right)')

    assert_equal (:x.l + (:y.l + (:z.l/3.l))).latex,
    parse_unparse('x+\left(y+\frac{z}{3}\right)')

    assert_equal (:x.l + (:y.l/(:z.l/3.l))).latex,
    parse_unparse('x+\frac{y}{\frac{z}{3}}')

    assert_equal (:x.l + (:y.l/(:z.l/(3.l + :i.l)))).latex,
    parse_unparse('x+\frac{y}{\frac{z}{3+i}}')

    assert_equal (:x.l / (:y.l + 2.l)).latex,
    parse_unparse('\frac{x}{y+2}')

    # frac inside paren
    assert_equal (2.l*(:x.l + 2.l/3.l)).latex,
    parse_unparse('2\cdot\left(x+\frac{2}{3}\right)')

    # paren inside frac
    assert_equal (:x.l / (2.l * (:y.l + 2.l))).latex,
    parse_unparse('\frac{x}{2\cdot\left(y+2\right)}')

    # frac inside paren inside frac
    assert_equal (2.l/(3.l*(:x.l+:y.l/5.l))).latex,
    parse_unparse('\frac{2}{3\cdot\left(x+\frac{y}{5}\right)}')
  end

  def test_parse_string_with_spaces
    assert_equal "This is a test of a string".l.latex,
    parse_unparse('This\ is\ a\ test\ of\ a\ string')

    assert_equal "This is a test of a string with ".l.space(1.l / 4.l).latex,
    parse_unparse('This\ is\ a\ test\ of\ a\ string\ with\ \frac{1}{4}')

    assert_equal "This is a test of a string with ".l.space(1.l / 4.l).space('in the middle'.l).latex,
    parse_unparse('This\ is\ a\ test\ of\ a\ string\ with\ \frac{1}{4}\ in\ the\ middle')

    assert_equal "This is a test of a string with ".l.space(1.l / 4.l).space('in the middle and with extraneous spaces'.l).latex,
    parse_unparse(' This\ is\ a\ test\ of\ a\ st r ing\ with\ \frac{1} {4} \ in\ the\ middle\ and\ with \  extraneous\ spaces ')

    assert_equal "This is a test of a string with a multiplication problem".l.space(3.l*4.2.l).space('and extra spaces'.l).latex,
    parse_unparse('This\ is\ a\ test\ of\ a\ string\ with\ a\ multiplication\ problem\ 3  \c  do t 4.2     \ and\ extra\ spaces')
  end

  def test_parse_eval
    assert_equal 5, "3+\\frac{4}{2}".parse_latex.eval
    assert_equal -1, "3+\\frac{4}{2}-6".parse_latex.eval
    assert_equal 13, "3+4^2-6".parse_latex.eval
    assert_equal 13, "3+4^\\frac{4}{2}-6".parse_latex.eval
  end

  def test_parse_latex
    assert_equal "3+\\frac{4}{2}", parse_unparse("3+\\frac{4}{2}")
    assert_equal "3+\\frac{4}{2}-6", parse_unparse("3+\\frac{4}{2}-6")
    # differences in next 2 cases due to how platform writes latex and how LaRuby outputs
    assert_equal "3+4^{2}-6", parse_unparse("3+4^2-6")
    assert_equal "3+4^{\\frac{4}{2}}-6", parse_unparse("3+4^\\frac{4}{2}-6")
  end

  def test_eval<commit_msg> add test case for glue<commit_after>require 'test_helper'

class TestLatexEval < MiniTest::Unit::TestCase
  def test_parse_nesting
    assert_equal (:x.l + (:y.l + (:z.l - 3.l))).latex,
    parse_unparse('x+\left(y+\left(z-3\right)\right)')

    assert_equal (:x.l + (:y.l + (:z.l/3.l))).latex,
    parse_unparse('x+\left(y+\frac{z}{3}\right)')

    assert_equal (:x.l + (:y.l/(:z.l/3.l))).latex,
    parse_unparse('x+\frac{y}{\frac{z}{3}}')

    assert_equal (:x.l + (:y.l/(:z.l/(3.l + :i.l)))).latex,
    parse_unparse('x+\frac{y}{\frac{z}{3+i}}')

    assert_equal (:x.l / (:y.l + 2.l)).latex,
    parse_unparse('\frac{x}{y+2}')

    # frac inside paren
    assert_equal (2.l*(:x.l + 2.l/3.l)).latex,
    parse_unparse('2\cdot\left(x+\frac{2}{3}\right)')

    # paren inside frac
    assert_equal (:x.l / (2.l * (:y.l + 2.l))).latex,
    parse_unparse('\frac{x}{2\cdot\left(y+2\right)}')

    # frac inside paren inside frac
    assert_equal (2.l/(3.l*(:x.l+:y.l/5.l))).latex,
    parse_unparse('\frac{2}{3\cdot\left(x+\frac{y}{5}\right)}')
  end

  def test_parse_string_with_spaces
    assert_equal "This is a test of a string".l.latex,
    parse_unparse('This\ is\ a\ test\ of\ a\ string')

    assert_equal "This is a test of a string with ".l.space(1.l / 4.l).latex,
    parse_unparse('This\ is\ a\ test\ of\ a\ string\ with\ \frac{1}{4}')

    assert_equal "This is a test of a string with ".l.space(1.l / 4.l).space('in the middle'.l).latex,
    parse_unparse('This\ is\ a\ test\ of\ a\ string\ with\ \frac{1}{4}\ in\ the\ middle')

    assert_equal "This is a test of a string with ".l.space(1.l / 4.l).space('in the middle and with extraneous spaces'.l).latex,
    parse_unparse(' This\ is\ a\ test\ of\ a\ st r ing\ with\ \frac{1} {4} \ in\ the\ middle\ and\ with \  extraneous\ spaces ')

    assert_equal "This is a test of a string with a multiplication problem".l.space(3.l*4.2.l).space('and extra spaces'.l).latex,
    parse_unparse('This\ is\ a\ test\ of\ a\ string\ with\ a\ multiplication\ problem\ 3  \c  do t 4.2     \ and\ extra\ spaces')

    assert_equal "This string doesn't have a space before the multiplication (".l.glue(3.l*4.l).glue(") or after".l).latex,
    parse_unparse('This\ string\ doesn\'t\ have\ a\ space\ before\ the\ multiplication\ (3\cdot 4)\ or\ after')
  end

  def test_parse_eval
    assert_equal 5, "3+\\frac{4}{2}".parse_latex.eval
    assert_equal -1, "3+\\frac{4}{2}-6".parse_latex.eval
    assert_equal 13, "3+4^2-6".parse_latex.eval
    assert_equal 13, "3+4^\\frac{4}{2}-6".parse_latex.eval
  end

  def test_parse_latex
    assert_equal "3+\\frac{4}{2}", parse_unparse("3+\\frac{4}{2}")
    assert_equal "3+\\frac{4}{2}-6", parse_unparse("3+\\frac{4}{2}-6")
    # differences in next 2 cases due to how platform writes latex and how LaRuby outputs
    assert_equal "3+4^{2}-6", parse_unparse("3+4^2-6")
    assert_equal "3+4^{\\frac{4}{2}}-6", parse_unparse("3+4^\\frac{4}{2}-6")
  end

  def test_eval
{'fraction_non_alphanumeric': 0.20729772607086197, 'fraction_numerical': 0.035607262471355546, 'mean_word_length': 3.108616944243302, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5968059', 'n_tokens_mistral': 2433, 'n_tokens_neox': 2320, 'n_words': 504}