<commit_before>class MrubyK2hashTest < MTest::Unit::TestCase
  K2HASH_FILENAME = '/tmp/mtest.k2hash'
  K2HASH_OTHER_FILENAME = '/tmp/mtest_other.k2hash'

  def test_open
    # TODO Assert error cases
    writer = K2Hash.new(K2HASH_FILENAME, 0666, K2Hash::WRITER)
    writer.store('key1', 'value1')
    writer.close

    reader = K2Hash.new(K2HASH_FILENAME, 0666, K2Hash::READER)
    assert_equal reader.fetch('key1'), 'value1'
    reader.close

    wrcreat = K2Hash.new(K2HASH_FILENAME, 0666, K2Hash::WRCREAT)
    assert_false wrcreat.empty?
    wrcreat.close

    newdb = K2Hash.new(K2HASH_FILENAME, 0666, K2Hash::NEWDB)
    assert_true newdb.empty?
    newdb.close
  end

  def test_clear
    k2hash = K2Hash.new(K2HASH_FILENAME, 0666, K2Hash::NEWDB)
    k2hash.store('key1', 'value1')
    k2hash.store('key2', 'value2')
    k2hash.store('key3', 'value3')

    k2hash.clear

    assert_equal k2hash.size, 0
  end

  def test_closed
    k2hash = K2Hash.new(K2HASH_FILENAME, 0666, K2Hash::NEWDB)
    k2hash.close<commit_msg>remove write-mode test case<commit_after>class MrubyK2hashTest < MTest::Unit::TestCase
  K2HASH_FILENAME = '/tmp/mtest.k2hash'
  K2HASH_OTHER_FILENAME = '/tmp/mtest_other.k2hash'

  def test_open
    init = K2Hash.new(K2HASH_FILENAME, 0666, K2Hash::NEWDB)
    init.store('key1', 'value1')
    init.close

    reader = K2Hash.new(K2HASH_FILENAME, 0666, K2Hash::READER)
    assert_equal reader.fetch('key1'), 'value1'
    reader.close

    wrcreat = K2Hash.new(K2HASH_FILENAME, 0666, K2Hash::WRCREAT)
    assert_false wrcreat.empty?
    wrcreat.close

    newdb = K2Hash.new(K2HASH_FILENAME, 0666, K2Hash::NEWDB)
    assert_true newdb.empty?
    newdb.close
  end

  def test_clear
    k2hash = K2Hash.new(K2HASH_FILENAME, 0666, K2Hash::NEWDB)
    k2hash.store('key1', 'value1')
    k2hash.store('key2', 'value2')
    k2hash.store('key3', 'value3')

    k2hash.clear

    assert_equal k2hash.size, 0
  end

  def test_closed
    k2hash = K2Hash.new(K2HASH_FILENAME, 0666, K2Hash::NEWDB)
    k2hash.close
{'fraction_non_alphanumeric': 0.11950617283950617, 'fraction_numerical': 0.06518518518518518, 'mean_word_length': 3.9174757281553396, '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': '485257', 'n_tokens_mistral': 903, 'n_tokens_neox': 832, 'n_words': 132}