<commit_before>require 'test_helper'
require 'ttnt/test_to_code_mapping'

class TestToCodeMappingTest < TTNT::TestCase
  def setup
    super
    @test_to_code_mapping = TTNT::TestToCodeMapping.new(@repo, @repo.head.target_id)
  end

  def test_append_from_coverage
    test_file = 'test/fizz_test.rb'
    # Not a valid coverage, but an example
    coverage = { "#{@repo.workdir}/lib/fizzbuzz.rb"=> [1, 1, nil, 1, 0, 1, 0, 1] }
    @test_to_code_mapping.append_from_coverage(test_file, coverage)
    expected_mapping = {
      test_file => { 'lib/fizzbuzz.rb' => [1, 2, 4, 6, 8] }
    }
    assert_equal expected_mapping, @test_to_code_mapping.read_mapping
  end

  def test_save_commit_info
    @test_to_code_mapping.save_commit_info(@repo.head.target_id)
    assert_equal @repo.head.target_id, File.read("#{@repo.workdir}/.ttnt/commit_obj.txt")
  end

  def test_get_tests
    test_file = 'test/fizz_test.rb'
    coverage = { "#{@repo.workdir}/lib/fizzbuzz.rb"=> [1, 1, nil, 1, 0, 1, 0, 1] }<commit_msg>Fix test so that it doesn't depend on fixture<commit_after>require 'test_helper'
require 'ttnt/test_to_code_mapping'

class TestToCodeMappingTest < TTNT::TestCase
  def setup
    super
    # These tests do not depend on fixture file
    File.delete("#{@repo.workdir}/.ttnt/test_to_code_mapping.json")
    @test_to_code_mapping = TTNT::TestToCodeMapping.new(@repo, @repo.head.target_id)
  end

  def test_append_from_coverage
    test_file = 'test/fizz_test.rb'
    # Not a valid coverage, but an example
    coverage = { "#{@repo.workdir}/lib/fizzbuzz.rb"=> [1, 1, nil, 1, 0, 1, 0, 1] }
    @test_to_code_mapping.append_from_coverage(test_file, coverage)
    expected_mapping = {
      test_file => { 'lib/fizzbuzz.rb' => [1, 2, 4, 6, 8] }
    }
    assert_equal expected_mapping, @test_to_code_mapping.read_mapping
  end

  def test_save_commit_info
    @test_to_code_mapping.save_commit_info(@repo.head.target_id)
    assert_equal @repo.head.target_id, File.read("#{@repo.workdir}/.ttnt/commit_obj.txt")
  end

  def test_get_tests
    test_file = 'test/fizz_test.rb'
    coverage = { "#{@repo.workdir}/lib/fizzbuzz.rb"=> [1, 1, nil, 1, 0, 1, 0, 1] }
{'fraction_non_alphanumeric': 0.1326530612244898, 'fraction_numerical': 0.017625231910946195, 'mean_word_length': 4.123515439429929, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '4807946', 'n_tokens_mistral': 867, 'n_tokens_neox': 827, 'n_words': 157}