<commit_before># frozen_string_literal: true

require File.expand_path('../../test_helper', File.dirname(__FILE__))

class RedisTest < Minitest::Test
  REDIS_STORAGE_FORMAT_VERSION = Coverband::Adapters::RedisStore::REDIS_STORAGE_FORMAT_VERSION

  def setup
    super
    Coverband.configuration.redis_namespace = 'coverband_test'
    @redis = Redis.new
    @store = Coverband::Adapters::RedisStore.new(@redis, redis_namespace: 'coverband_test')
    Coverband.configuration.store = @store
    @store.clear!
  end

  def test_coverage
    mock_file_hash
    expected = basic_coverage
    @store.save_report(expected)
    assert_equal expected.keys, @store.coverage.keys
    @store.coverage.each_pair do |key, data|
      assert_equal expected[key], data['data']
    end
  end

  def test_coverage_increments
    mock_file_hash
    expected = basic_coverage.dup
    @store.save_report(basic_coverage.dup)
    assert_equal expected.keys, @store.coverage.keys
    @store.coverage.each_pair do |key, data|
      assert_equal expected[key], data['data']
    end
    @store.save_report(basic_coverage.dup)
    assert_equal [0, 2, 4], @store.coverage['app_path/dog.rb']['data']
  end

  def test_store_coverage_by_type
    mock_file_hash
    expected = basic_coverage
    @store.type = :eager_loading
    @store.save_report(expected)
    assert_equal expected.keys, @store.coverage.keys
    @store.coverage.each_pair do |key, data|
      assert_equal expected[key], data['data']
    end

    @store.type = Coverband::RUNTIME_TYPE
    assert_equal [], @store.coverage.keys
  end

  def test_merged_coverage_with_types
    mock_file_hash
    assert_equal Coverband::RUNTIME_TYPE, @store.type
    @store.type = :eager_loading
    @store.save_report('app_path/dog.rb' => [0, 1, 1])
    @store.type = Coverband::RUNTIME_TYPE
    @store.save_report('app_path/dog.rb' => [1, 0, 1])
    assert_equal [1, 1, 2], @store.get_coverage_report[:merged]['app_path/dog.rb']['data']
    assert_equal Coverband::RUNTIME_TYPE, @store.type
  end

  def test_coverage_for_file
    mock_file_hash
    expected = basic_coverage
    @store.save_report(expected)
    assert_equal example_line, @store.coverage['app_path/dog.rb']['data']
  end

  def test_coverage_when_null
    assert_nil @store.coverage['app_path/dog.rb']
  end

  def test_clear
    @redis.expects(:del).twice
    @store.clear!
  end
end<commit_msg>fix test<commit_after># frozen_string_literal: true

require File.expand_path('../../test_helper', File.dirname(__FILE__))

class RedisTest < Minitest::Test
  REDIS_STORAGE_FORMAT_VERSION = Coverband::Adapters::RedisStore::REDIS_STORAGE_FORMAT_VERSION

  def setup
    super
    Coverband.configuration.redis_namespace = 'coverband_test'
    @redis = Redis.new
    @store = Coverband::Adapters::RedisStore.new(@redis, redis_namespace: 'coverband_test')
    Coverband.configuration.store = @store
    @store.clear!
  end

  def test_coverage
    mock_file_hash
    expected = basic_coverage
    @store.save_report(expected)
    assert_equal expected.keys, @store.coverage.keys
    @store.coverage.each_pair do |key, data|
      assert_equal expected[key], data['data']
    end
  end

  def test_coverage_increments
    mock_file_hash
    expected = basic_coverage.dup
    @store.save_report(basic_coverage.dup)
    assert_equal expected.keys, @store.coverage.keys
    @store.coverage.each_pair do |key, data|
      assert_equal expected[key], data['data']
    end
    @store.save_report(basic_coverage.dup)
    assert_equal [0, 2, 4], @store.coverage['app_path/dog.rb']['data']
  end

  def test_store_coverage_by_type
    mock_file_hash
    expected = basic_coverage
    @store.type = :eager_loading
    @store.save_report(expected)
    assert_equal expected.keys, @store.coverage.keys
    @store.coverage.each_pair do |key, data|
      assert_equal expected[key], data['data']
    end

    @store.type = Coverband::RUNTIME_TYPE
    assert_equal [], @store.coverage.keys
  end

  def test_merged_coverage_with_types
    mock_file_hash
    assert_equal Coverband::RUNTIME_TYPE, @store.type
    @store.type = :eager_loading
    @store.save_report('app_path/dog.rb' => [0, 1, 1])
    @store.type = Coverband::RUNTIME_TYPE
    @store.save_report('app_path/dog.rb' => [1, 0, 1])
    assert_equal [1, 1, 2], @store.get_coverage_report[:merged]['app_path/dog.rb']['data']
    assert_equal Coverband::RUNTIME_TYPE, @store.type
  end

  def test_coverage_for_file
    mock_file_hash
    expected = basic_coverage
    @store.save_report(expected)
    assert_equal example_line, @store.coverage['app_path/dog.rb']['data']
  end

  def test_coverage_when_null
    assert_nil @store.coverage['app_path/dog.rb']
  end

  def test_clear
    @redis.expects(:del).times(3)
    @store.clear!
  end
end
{'fraction_non_alphanumeric': 0.11325503355704698, 'fraction_numerical': 0.005243288590604027, 'mean_word_length': 4.1501079913606915, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5820883', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1641, 'n_words': 280}