<commit_before>require 'minitest_helper'

class TestGrnMiniArray < MiniTest::Unit::TestCase
  def test_empty
    GrnMini::Array.tmpdb do |array|
      assert_equal true, array.empty?
    end 
  end
end<commit_msg>Add TestGrnMiniArray tests<commit_after>require 'minitest_helper'

class TestGrnMiniArray < MiniTest::Unit::TestCase
  def test_initialize
    Dir.mktmpdir do |dir|
      array = GrnMini::Array.new(File.join(dir, "test.db"))
    end
  end

  def test_add
    GrnMini::Array.tmpdb do |array|
      array << {text:"aaa", number:1}
      assert_equal 1, array.size

      array << {text:"bbb", number:2}
      assert_equal 2, array.size
    end 
  end

  def test_select
    GrnMini::Array.tmpdb do |array|
      array << {text:"aaa", number:1}
      array << {text:"bbb", number:2}
      array << {text:"ccc", number:3}

      results = array.select("bb")

      assert_equal 1, results.size
      assert_equal "bbb", results.first.text
    end 
  end

  def test_select2
    GrnMini::Array.tmpdb do |array|
      array << {text:"aaa", number:1}
      array << {text:"bbb", number:2}
      array << {text:"bbb", number:20}
      array << {text:"ccc", number:3}

      results = array.select("bb number:<10")

      assert_equal 1, results.size
      assert_equal "bbb", results.first.text
      assert_equal 2, results.first.number
    end 
  end

  def test_size
    GrnMini::Array.tmpdb do |array|
      assert_equal 0, array.size
      
      array << {text:"aaa", number:1}
      array << {text:"bbb", number:2}
      assert_equal 2, array.size
    end
  end

  def test_empty?
    GrnMini::Array.tmpdb do |array|
      assert_equal true, array.empty?

      array << {text:"aaa", number:1}
      assert_equal false, array.empty?
    end
  end

  def test_each
    GrnMini::Array.tmpdb do |array|
      array << {text:"aaa", number:1}
      array << {text:"bbb", number:2}
      array << {text:"ccc", number:3}

      array.each_with_index do |v, index|
        case index
        when 0
          assert_equal "aaa", v.text
          assert_equal 1, v.number
        when 1
          assert_equal "bbb", v.text
          assert_equal 2, v.number
        when 2
          assert_equal "ccc", v.text
          assert_equal 3, v.number
        end
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.12101354303189166, 'fraction_numerical': 0.013979903888160769, 'mean_word_length': 2.4696969696969697, 'pattern_counts': {'":': 0, '<': 36, '<?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': '213963', 'n_tokens_mistral': 820, 'n_tokens_neox': 765, 'n_words': 190}