<commit_before>require 'ostruct'
require 'json'

class ExerciseCase < OpenStruct
  using Generator::Underscore

  def name
    'test_%s' % description.underscore
  end

  def skipped
    index.zero? ? '# skip' : 'skip'
  end

  protected

  # used in workload, for example, as
  #   "#{assert} Luhn.valid?(#{input.inspect})"
  def assert
    expected ? 'assert' : 'refute'
  end

  # used in workload, for example, as
  #   assert_equal { "PigLatin.translate(#{input.inspect})" }
  def assert_equal
    "assert_equal #{expected.inspect}, #{yield}"
  end

  # used in workload, for example, as
  #   if raises_error?
  #     assert_raises(ArgumentError) { test_case }
  #   else
  #     assert_equal { test_case }
  #   end

  def raises_error?
    expected.to_i == -1
  end

  def assert_raises(error)
    "assert_raises(#{error}) { #{yield} }"
  end
end
<commit_msg>add indentation helper for multi-line workloads<commit_after>require 'ostruct'
require 'json'

class ExerciseCase < OpenStruct
  using Generator::Underscore

  def name
    'test_%s' % description.underscore
  end

  def skipped
    index.zero? ? '# skip' : 'skip'
  end

  protected

  # used to indent multi line workloads, as
  #   indent_lines(
  #     [
  #       "string = #{input.inspect}",
  #       "#{assert} Isogram.is_isogram?(string)"
  #     ], 4
  #   )
  def indent_lines(code, depth)
    code.join("\n" + ' ' * depth)
  end

  # used in workload, for example, as
  #   "#{assert} Luhn.valid?(#{input.inspect})"
  def assert
    expected ? 'assert' : 'refute'
  end

  # used in workload, for example, as
  #   assert_equal { "PigLatin.translate(#{input.inspect})" }
  def assert_equal
    "assert_equal #{expected.inspect}, #{yield}"
  end

  # used in workload, for example, as
  #   if raises_error?
  #     assert_raises(ArgumentError) { test_case }
  #   else
  #     assert_equal { test_case }
  #   end

  def raises_error?
    expected.to_i == -1
  end

  def assert_raises(error)
    "assert_raises(#{error}) { #{yield} }"
  end
end

{'fraction_non_alphanumeric': 0.12641975308641976, 'fraction_numerical': 0.0014814814814814814, 'mean_word_length': 2.9881889763779528, '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': '3806867', 'n_tokens_mistral': 739, 'n_tokens_neox': 710, 'n_words': 172}