<commit_before>require 'test_helper'
require 'simple_enum/enum_hash'

class EnumHashTest < MiniTest::Unit::TestCase
  
  def test_create_new_enumhash_instance_from_array_of_symbols
    genders = SimpleEnum::EnumHash.new [:male, :female]
    
    assert_same 0, genders[:male]
    assert_same 1, genders[:female]
    assert_same 0, genders.male
    assert_same :female, genders.female(true)
  end

  def test_create_new_enumhash_instance_from_hash
    status = SimpleEnum::EnumHash.new :inactive => 0, :active => 1, :archived => 99
    
    assert_same 0, status.inactive
    assert_same 1, status[:active]
  end
  
  def test_create_new_enumhash_instance_from_query_results
    reload_db :genders => true
    genders = SimpleEnum::EnumHash.new Gender.all
        
    assert_same 0, genders[@male]
    assert_same genders[@male], genders[:male]
    assert_same 1, genders.female
    assert_equal @male, genders.send(:male, true)
  end
  
  def test_that_enumhash_keys_are_ordered
    ordered = SimpleEnum::EnumHash.new [:alpha, :beta, :gamma, :delta, :epsilon, :zeta, :eta]
    expected_keys = [:alpha, :beta, :gamma, :delta, :epsilon, :zeta, :eta]
    assert_equal expected_keys, ordered.keys
  end
  
  def test_valid_key_value_association_when_simple_array_is_merged_into_enumhash
    a = [:a, :b, :c, :d]
    h = SimpleEnum::EnumHash.new(a)
    
    assert_same 0, h[:a]
    assert_same 1, h[:b]
    assert_same 2, h[:c]
    assert_same 3, h[:d]
    assert_equal [:a, :b, :c, :d], h.keys
  end
  
  def test_that_an_already_correct_looking_array_is_converted_to_hash
    a = [[:a, 5], [:b, 10]]
    h = SimpleEnum::EnumHash.new(a)
    
    assert_same 5, h[:a]
    assert_same 10, h[:b]
    assert_equal [:a, :b], h.keys
  end
  
  def test_that_an_array_of_query_results_are_converted_to_result_ids
    reload_db :genders => true # reload db
    a = Gender.all
    
    h = SimpleEnum::EnumHash.new(a)
    
    assert_same 0, h[@male]
    assert_same 1, h[@female]
  end  
end<commit_msg>added missing test for strings param in EnumHash<commit_after>require 'test_helper'
require 'simple_enum/enum_hash'

class EnumHashTest < MiniTest::Unit::TestCase

  def test_create_new_enumhash_instance_from_array_of_symbols
    genders = SimpleEnum::EnumHash.new [:male, :female]

    assert_same 0, genders[:male]
    assert_same 1, genders[:female]
    assert_same 0, genders.male
    assert_same :female, genders.female(true)
  end

  def test_create_new_enumhash_instance_from_hash
    status = SimpleEnum::EnumHash.new :inactive => 0, :active => 1, :archived => 99

    assert_same 0, status.inactive
    assert_same 1, status[:active]
  end

  def test_create_new_enumhash_instance_from_query_results
    reload_db :genders => true
    genders = SimpleEnum::EnumHash.new Gender.all

    assert_same 0, genders[@male]
    assert_same genders[@male], genders[:male]
    assert_same 1, genders.female
    assert_equal @male, genders.send(:male, true)
  end

  def test_that_enumhash_keys_are_ordered
    ordered = SimpleEnum::EnumHash.new [:alpha, :beta, :gamma, :delta, :epsilon, :zeta, :eta]
    expected_keys = [:alpha, :beta, :gamma, :delta, :epsilon, :zeta, :eta]
    assert_equal expected_keys, ordered.keys
  end

  def test_valid_key_value_association_when_simple_array_is_merged_into_enumhash
    a = [:a, :b, :c, :d]
    h = SimpleEnum::EnumHash.new(a)

    assert_same 0, h[:a]
    assert_same 1, h[:b]
    assert_same 2, h[:c]
    assert_same 3, h[:d]
    assert_equal [:a, :b, :c, :d], h.keys
  end

  def test_that_an_already_correct_looking_array_is_converted_to_hash
    a = [[:a, 5], [:b, 10]]
    h = SimpleEnum::EnumHash.new(a)

    assert_same 5, h[:a]
    assert_same 10, h[:b]
    assert_equal [:a, :b], h.keys
  end

  def test_that_an_array_of_query_results_are_converted_to_result_ids
    reload_db :genders => true # reload db
    a = Gender.all

    h = SimpleEnum::EnumHash.new(a)

    assert_same 0, h[@male]
    assert_same 1, h[@female]
  end

  def test_strings_option
    h = SimpleEnum::EnumHash.new([:male, :female], true)
    assert_equal "male", h[:male]
    assert_equal "female", h[:female]
  end
end
{'fraction_non_alphanumeric': 0.1116751269035533, 'fraction_numerical': 0.011119168479574571, 'mean_word_length': 4.021844660194175, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '5288263', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1498, 'n_words': 329}