<commit_before># encoding: utf-8

require 'test/unit'
$:.push(File.join('..', 'lib'))
require 'weightedarray'

class WeightedArrayTest < Test::Unit::TestCase

  def setup
    @wa = WeightedArray.new(['Anton', 'Berti', 'Conni'])
    begin
      $stderr = File.open('/tmmp/weightedarraytestoutput.txt', 'w')
    rescue
    end
  end

  def test_initialize
    assert_equal( 'Berti', @wa[1] )
    assert_equal( 1, @wa.weight_of('Berti') )
  end

  def test_change_weight
    @wa.upgrade('Anton')
    assert_equal( 2, @wa.weight['Anton'] )
    @wa.upgrade('Berti', 9)
    assert_equal( 10, @wa.weight['Berti'] )
  end

  def test_push
    @wa.push( 'Det', 100 )
    assert_equal( 4, @wa.length )
    assert_raise(InvalidWeightError) { @wa.push('Fritzchen', -3) }
    $stderr.puts('Ignore the following warning when testing:')
    assert_nothing_raised { @wa.push('Edi', 10.5) }
    assert_equal(11, @wa.weight_of('Edi'))
  end

end

<commit_msg>Setting $stderr to a file and, after tests, back to previous value.<commit_after># encoding: utf-8

require 'test/unit'
$:.push(File.join('..', 'lib'))
require 'weightedarray'

class WeightedArrayTest < Test::Unit::TestCase

  def setup
    @wa = WeightedArray.new(['Anton', 'Berti', 'Conni'])
    @tmp_file = '/tmp/weightedarraytestoutput.txt'
    begin
      @old_stderr = $stderr
      $stderr = File.open(@tmp_file, 'w')
    rescue
    end
  end

  def teardown
    begin
      $stderr = @old_stderr
      File.delete(@tmp_file)
    rescue
    end
  end

  def test_initialize
    assert_equal( 'Berti', @wa[1] )
    assert_equal( 1, @wa.weight_of('Berti') )
  end

  def test_change_weight
    @wa.upgrade('Anton')
    assert_equal( 2, @wa.weight['Anton'] )
    @wa.upgrade('Berti', 9)
    assert_equal( 10, @wa.weight['Berti'] )
  end

  def test_push
    @wa.push( 'Det', 100 )
    assert_equal( 4, @wa.length )
    assert_raise(InvalidWeightError) { @wa.push('Fritzchen', -3) }
    $stderr.puts('Ignore the following warning when testing:')
    assert_nothing_raised { @wa.push('Edi', 10.5) }
    assert_equal(11, @wa.weight_of('Edi'))
  end

end


{'fraction_non_alphanumeric': 0.15784453981878874, 'fraction_numerical': 0.016213638531235097, 'mean_word_length': 3.454352441613588, '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': '4197524', 'n_tokens_mistral': 815, 'n_tokens_neox': 756, 'n_words': 164}