<commit_before>require 'test_helper'

class TypeTest < Test::Unit::TestCase
  context "Test with differents Types" do
    #TODO figure out how to have one setup and one teardown
    setup do
      @client = ElasticSearch.new('127.0.0.1:9200', :index => "twitter", :type => "tweet")
      @client.index({:user => "kimchy"}, :id => 1)
      @client.index({:user => "kimchy"}, :id => 2, :type => "grillo")
      @client.index({:user => "kimchy"}, :id => 3, :type => "cote")
      @client.index({:user => "kimchy"}, :id => 4, :index => "cotes", :type => "cote")
      @client.index({:user => "kimchy"}, :id => 5, :index => "menchos", :type => "mencho")
      @client.index({:user => "kimchy"}, :id => 6, :index => "menchos", :type => "cote")
      @client.refresh("twitter", "cotes", "menchos")
    end

    teardown do
      #@client.delete_index("twitter")
      #@client.delete_index("cotes")
      #@client.delete_index("menchos")
    end

    should "search in all indexes" do
      assert_equal @client.count("kimchy",{:index => "", :type => ""}), 6
    end
    
    should "search in all types with index twitter" do
      assert_equal @client.count("kimchy",{:index => "twitter", :type => ""}), 3
    end
    
    should "search in index twitter with types tweet,cote" do
      assert_equal @client.count("kimchy",{:index => "twitter", :type => "tweet,cote"}), 2
    end
    
    should "search in index twitter,cotes" do
      assert_equal @client.count("kimchy",{:index => "twitter,cotes",  :type => ""}), 4
    end
    
    should "search in types grillo,cote of all indexes" do
      assert_equal @client.count("kimchy",{:index => "",  :type => "grillo,cote"}), 4
    end
    
  end
end<commit_msg>@improve type_test.rb have one setup and one teardown<commit_after>require 'test_helper'

class TypeTest < Test::Unit::TestCase
  context "Test with differents Types" do

    setup do
      @first_index = 'first-' + Time.now.to_i.to_s
      @second_index = 'second-' + Time.now.to_i.to_s
      @third_index = 'third-' + Time.now.to_i.to_s
      @client = ElasticSearch.new('127.0.0.1:9200', :index => @first_index, :type => "tweet")
      @client.index({:user => "kimchy"}, :id => 1)
      @client.index({:user => "kimchy"}, :id => 2, :type => "grillo")
      @client.index({:user => "kimchy"}, :id => 3, :type => "cote")
      @client.index({:user => "kimchy"}, :id => 4, :index => @second_index, :type => "cote")
      @client.index({:user => "kimchy"}, :id => 5, :index => @third_index, :type => "mencho")
      @client.index({:user => "kimchy"}, :id => 6, :index => @third_index, :type => "cote")
      @client.refresh(@first_index, @second_index, @third_index)
    end

    teardown do
      @client.delete_index(@first_index)
      @client.delete_index(@second_index)
      @client.delete_index(@third_index)
    end

    should "Test different stages using indexes and types" do
      # Search in all indexes
      assert_equal @client.count("kimchy",{:index => "", :type => ""}), 6
      
      # Search in all types with index first
      assert_equal @client.count("kimchy",{:index => @first_index, :type => ""}), 3
      
      # Search in first index with types tweet,cote
      assert_equal @client.count("kimchy",{:index => @first_index, :type => "tweet,cote"}), 2
      
      # Search in index first and second
      @first_and_second = @first_index + ',' + @second_index  
      assert_equal @client.count("kimchy",{:index => @first_and_second,  :type => ""}), 4
      
      # Search in types grillo,cote of all indexes" do
      assert_equal @client.count("kimchy",{:index => "",  :type => "grillo,cote"}), 4
    end

  end
end
{'fraction_non_alphanumeric': 0.18428258488499452, 'fraction_numerical': 0.011500547645125958, 'mean_word_length': 3.267523364485981, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1501229', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1223, 'n_words': 307}