<commit_before># encoding: utf-8

require_relative 'test_helper'

class IntegrationTest < MiniTest::Unit::TestCase
  class Collection
    include Curio.new(:id)
  end

  Item = Struct.new(:id)

  attr_reader :collection

  def setup
    @collection = Collection.new
  end

  def test_enumerable_behavior
    assert_kind_of Enumerable, collection
    assert_instance_of Enumerator, collection.each
  end

  def test_retrieving_last_item
    item1 = Item.new 1
    item2 = Item.new 2
    collection << item1 << item2

    assert_equal item2, collection.last
  end

  def test_retriving_all_items
    item1 = Item.new 1
    item2 = Item.new 2
    collection << item1 << item2

    assert_equal [item1, item2], collection.all
    assert_equal [item1, item2], collection.values
  end

  def test_retrieving_item
    item = Item.new 'a'
    collection << item

    found = collection['a']
    assert_equal item, found

    found = collection.fetch 'a'
    assert_equal item, found
  end

  def test_retrieving_unknown_item
    found = collection['a']
    assert_equal nil, found

    assert_raises Curio::NotFoundError do
      collection.fetch 'a'
    end

    found = collection.fetch 'a', 'bang'
    assert_equal 'bang', found

    found = collection.fetch('a') { 'bang' }
    assert_equal 'bang', found
  end

  def test_adding_an_item
    item = Item.new 1

    assert_equal 0, collection.count
    collection << item
    assert_includes collection, item
    assert_equal 1, collection.count
  end

  def test_item_is_known
    item = Item.new 'a'
    collection << item

    assert collection.key? 'a'
    assert collection.has? 'a'
    refute collection.key? 'b'
    refute collection.has? 'b'
  end

  def test_hash_representation
    item1 = Item.new 'a'
    item2 = Item.new 'b'
    collection << item1 << item2

    assert_equal({
      'a' => item1,
      'b' => item2
    }, collection.to_h)
  end
end
<commit_msg>test: add key coercion test<commit_after># encoding: utf-8

require_relative 'test_helper'

class IntegrationTest < MiniTest::Unit::TestCase
  class Collection
    include Curio.new(:id)
  end

  Item = Struct.new(:id)

  attr_reader :collection

  def setup
    @collection = Collection.new
  end

  def test_enumerable_behavior
    assert_kind_of Enumerable, collection
    assert_instance_of Enumerator, collection.each
  end

  def test_retrieving_last_item
    item1 = Item.new 1
    item2 = Item.new 2
    collection << item1 << item2

    assert_equal item2, collection.last
  end

  def test_retriving_all_items
    item1 = Item.new 1
    item2 = Item.new 2
    collection << item1 << item2

    assert_equal [item1, item2], collection.all
    assert_equal [item1, item2], collection.values
  end

  def test_retrieving_item
    item = Item.new 'a'
    collection << item

    found = collection['a']
    assert_equal item, found

    found = collection.fetch 'a'
    assert_equal item, found
  end

  def test_retrieving_unknown_item
    found = collection['a']
    assert_equal nil, found

    assert_raises Curio::NotFoundError do
      collection.fetch 'a'
    end

    found = collection.fetch 'a', 'bang'
    assert_equal 'bang', found

    found = collection.fetch('a') { 'bang' }
    assert_equal 'bang', found
  end

  def test_adding_an_item
    item = Item.new 1

    assert_equal 0, collection.count
    collection << item
    assert_includes collection, item
    assert_equal 1, collection.count
  end

  def test_item_is_known
    item = Item.new 'a'
    collection << item

    assert collection.key? 'a'
    assert collection.has? 'a'
    refute collection.key? 'b'
    refute collection.has? 'b'
  end

  def test_hash_representation
    item1 = Item.new 'a'
    item2 = Item.new 'b'
    collection << item1 << item2

    assert_equal({
      'a' => item1,
      'b' => item2
    }, collection.to_h)
  end

  def test_coerces_key
    item = Item.new 1
    collection << item

    found = collection.fetch '1'
    assert_equal item, found

    found = collection.fetch :'1'
    assert_equal item, found
  end
end

{'fraction_non_alphanumeric': 0.08575653031049778, 'fraction_numerical': 0.014046328240512568, 'mean_word_length': 2.9369544131910765, 'pattern_counts': {'":': 0, '<': 43, '<?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': '6506262', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1294, 'n_words': 360}