<commit_before>require 'utils/compilers'

class Question < ApplicationRecord
  include Compilers

  validates_presence_of :description

  belongs_to :exercise
  has_many :test_cases

  # Run the source code with the specified input of each test case and check
  # its output.
  def test_all(file_name, file_ext, source_code)
    results = []
    self.test_cases.each do |test_case|
      output = run(file_name, file_ext, source_code, test_case.input)
      if has_error? || output != test_case.output
        results << { title: test_case.title, status: :error, output: output }
      else
        results << { title: test_case.title, status: :success, output: output }
      end
    end
    results
  end
end<commit_msg>Fix file_name bug<commit_after>require 'utils/compilers'

class Question < ApplicationRecord
  include Compilers

  validates_presence_of :description

  belongs_to :exercise
  has_many :test_cases

  # Run the source code with the specified input of each test case and check
  # its output.
  def test_all(file_name, file_ext, source_code)
    results = []
    self.test_cases.each_with_index do |test_case, index|
      # 'file_name' must be composed by the index to avoid that 'run' method
      # doesn't write the compiler output in the same file.
      output = run("#{file_name}_#{index}", file_ext, source_code, test_case.input)
      if has_error? || output != test_case.output
        results << { title: test_case.title, status: :error, output: output }
      else
        results << { title: test_case.title, status: :success, output: output }
      end
    end
    results
  end
end
{'fraction_non_alphanumeric': 0.08348794063079777, 'fraction_numerical': 0.0, 'mean_word_length': 3.420765027322404, 'pattern_counts': {'":': 0, '<': 13, '<?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': '1320162', 'n_tokens_mistral': 491, 'n_tokens_neox': 484, 'n_words': 155}