<commit_before># -*- coding: utf-8 -*-
#
# class GroongaSearcherTest
#
# Copyright (C) 2015-2016  <NAME> <<EMAIL>>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

require "feedcellar/groonga_database"
require "feedcellar/groonga_searcher"

class GroongaSearcherTest < Test::Unit::TestCase
  def setup
    @tmpdir = File.join(File.dirname(__FILE__), "tmp")
    FileUtils.rm_rf(@tmpdir)
    FileUtils.mkdir_p(@tmpdir)
    ENV["FEEDCELLAR_HOME"] = @tmpdir
    @database = Feedcellar::GroongaDatabase.new
    @database.open(@tmpdir)
  end

  def teardown
    @database.close
    FileUtils.rm_rf(@tmpdir)
  end

  class SearchTest < self
    def setup
      super
      @database.add("key1",
                    "Title1",
                    "http://null.myokoym.net/1",
                    "The site is fiction.",
                    Time.new(2014, 2, 5))
      @database.add("key2",
                    "Title2",
                    "http://null.myokoym.net/2",
                    "The site is fiction.",
                    Time.new(2015, 3, 6))
    end

    def test_all_records
      feeds = Feedcellar::GroongaSearcher.search(@database, [])
      assert_equal(2, feeds.size)
    end

    def test_found
      words = []
      words << "fiction"
      feeds = Feedcellar::GroongaSearcher.search(@database, words)
      assert_equal(2, feeds.size)
    end

    def test_and
      words = []
      words << "fiction"
      words << "Title1"
      feeds = Feedcellar::GroongaSearcher.search(@database, words)
      assert_equal(["Title1"], feeds.map(&:title))
    end

    def test_or
      words = []
      words << "Title1"
      words << "OR"
      words << "Title2"
      feeds = Feedcellar::GroongaSearcher.search(@database, words)
      assert_equal(["Title1", "Title2"], feeds.map(&:title).sort)
    end

    def test_year_found
      options = {
        :year => 2014,
      }
      feeds = Feedcellar::GroongaSearcher.search(@database, [], options)
      assert_equal(1, feeds.size)
    end

    def test_year_not_found
      options = {
        :year => 2013,
      }
      feeds = Feedcellar::GroongaSearcher.search(@database, [], options)
      assert_equal(0, feeds.size)
    end

    def test_month_found
      options = {
        :month => 2,
      }
      feeds = Feedcellar::GroongaSearcher.search(@database, [], options)
      assert_equal(1, feeds.size)
    end

    def test_month_not_found
      options = {
        :year => 3,
      }
      feeds = Feedcellar::GroongaSearcher.search(@database, [], options)
      assert_equal(0, feeds.size)
    end

    def test_year_and_month
      options = {
        :year => 2014,
        :month => 2,
      }
      feeds = Feedcellar::GroongaSearcher.search(@database, [], options)
      assert_equal(1, feeds.size)
    end
  end
end<commit_msg>test: Make results readable<commit_after># -*- coding: utf-8 -*-
#
# class GroongaSearcherTest
#
# Copyright (C) 2015-2016  <NAME> <<EMAIL>>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

require "feedcellar/groonga_database"
require "feedcellar/groonga_searcher"

class GroongaSearcherTest < Test::Unit::TestCase
  def setup
    @tmpdir = File.join(File.dirname(__FILE__), "tmp")
    FileUtils.rm_rf(@tmpdir)
    FileUtils.mkdir_p(@tmpdir)
    ENV["FEEDCELLAR_HOME"] = @tmpdir
    @database = Feedcellar::GroongaDatabase.new
    @database.open(@tmpdir)
  end

  def teardown
    @database.close
    FileUtils.rm_rf(@tmpdir)
  end

  class SearchTest < self
    def setup
      super
      @database.add("key1",
                    "Title1",
                    "http://null.myokoym.net/1",
                    "The site is fiction.",
                    Time.new(2014, 2, 5))
      @database.add("key2",
                    "Title2",
                    "http://null.myokoym.net/2",
                    "The site is fiction.",
                    Time.new(2015, 3, 6))
    end

    def test_all_records
      feeds = Feedcellar::GroongaSearcher.search(@database, [])
      assert_equal(2, feeds.size)
    end

    def test_found
      words = []
      words << "fiction"
      feeds = Feedcellar::GroongaSearcher.search(@database, words)
      assert_equal(2, feeds.size)
    end

    def test_and
      words = []
      words << "fiction"
      words << "Title1"
      feeds = Feedcellar::GroongaSearcher.search(@database, words)
      assert_equal(["Title1"], feeds.map(&:title))
    end

    def test_or
      words = []
      words << "Title1"
      words << "OR"
      words << "Title2"
      feeds = Feedcellar::GroongaSearcher.search(@database, words)
      assert_equal(["Title1", "Title2"], feeds.map(&:title).sort)
    end

    def test_year_found
      options = {
        :year => 2014,
      }
      feeds = Feedcellar::GroongaSearcher.search(@database, [], options)
      assert_equal(["Title1"], feeds.map(&:title))
    end

    def test_year_not_found
      options = {
        :year => 2013,
      }
      feeds = Feedcellar::GroongaSearcher.search(@database, [], options)
      assert_equal(0, feeds.size)
      assert_equal([], feeds.map(&:title))
    end

    def test_month_found
      options = {
        :month => 2,
      }
      feeds = Feedcellar::GroongaSearcher.search(@database, [], options)
      assert_equal(1, feeds.size)
      assert_equal(["Title1"], feeds.map(&:title))
    end

    def test_month_not_found
      options = {
        :year => 3,
      }
      feeds = Feedcellar::GroongaSearcher.search(@database, [], options)
      assert_equal(0, feeds.size)
      assert_equal([], feeds.map(&:title))
    end

    def test_year_and_month
      options = {
        :year => 2014,
        :month => 2,
      }
      feeds = Feedcellar::GroongaSearcher.search(@database, [], options)
      assert_equal(["Title1"], feeds.map(&:title))
    end
  end
end
{'fraction_non_alphanumeric': 0.1146487920681469, 'fraction_numerical': 0.019131406228180423, 'mean_word_length': 2.5159548355424644, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 21, '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': '7033085', 'n_tokens_mistral': 2378, 'n_tokens_neox': 2211, 'n_words': 576}