<commit_before>class Test::Unit::TestCase
  def self.veneer_should_implement_find
    context "implements find" do
      setup do
        Veneer(@klass).destroy_all
        (0..5).each do |i|
          Veneer(@klass).new(:order_field1 => i).save!
        end
      end

      teardown{ Veneer(@klass).destroy_all }

      should "impelement a find_all method" do
        result = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
        assert_kind_of Array, result
      end

      should "implement a find_first method" do
        result = Veneer(@klass).find_first(Veneer::Conditional.from_hash({}))
      end

      should "implement limit" do
        total = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
        assert_not_equal 3, total.size
        result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:limit => 3))
        assert_equal 3, result.size
      end

      should "implement order" do
        result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:order => "order_field1 asc"))
        raw = result.map{|i| i.order_field1 }.compact
        sorted = raw.sort
        assert_equal raw, sorted
      end

      should "implement asc and desc order as opposites" do
        result_asc  = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:order => "order_field1 asc")).map{|o| o.order_field1}
        result_desc = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:order => "order_field1 desc")).map{|o| o.order_field1}

        assert_equal result_asc, result_desc.reverse
      end

      should "implement order decending" do
        result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:order => "order_field1 desc"))
        raw = result.map{|i| i.order_field1 }.compact
        sorted = raw.sort.reverse
        assert_equal raw, sorted
      end

      should "implement order ascending" do
        result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:order => "order_field1 asc"))
        raw = result.map{|i| i.order_field1}.compact
        sorted = raw.sort
        assert_equal raw, sorted
      end

      should "impelment offset" do
        total = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
        result = Veneer(@klass).find_many(Veneer::Conditional.from_hash({:offset => 2, :limit => 2}))

        assert_equal((total[2..3]), result)
      end

      context "conditions" do
        setup do
          Veneer(@klass).new(:name => "bar").save
          Veneer(@klass).new(:name => "foo").save
          Veneer(@klass).new(:name => "foobar").save
        end

        should "implement basic conditions" do
          total = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
          result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:conditions => {:name => "foo"}))
          assert_equal 1, result.size
        end

        should "implement :not conditions" do
          Veneer(@klass).all(:conditions => {:name => nil}).map(&:destroy)
          total = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
          result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:conditions => {"name not" => "bar"}))
          assert_equal((total.size - 1), result.size)
        end

        should "implement gt conditions" do
          total = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
          expected = total.select{|i| !i.order_field1.nil? && i.order_field1 > 3}
          result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:conditions => {"order_field1 gt" => 3}))
          assert_equal expected.size, result.size
        end

        should "implement gte conditions" do
          total = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
          expected = total.select{|i| !i.order_field1.nil? && i.order_field1 >= 3}
          result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:conditions => {"order_field1 gte" => 3}))
          assert_equal 3, result.size
        end

        should "implement :lt condition" do
          result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:conditions => {"order_field1 lt" => 3}))
          assert_equal 3, result.size
        end

        should "implement a lte condition" do
          total     = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
          expected  = total.select{|i| !i.order_field1.nil? && i.order_field1 <= 3}
          result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:conditions => {"order_field1 lte" => 3}))
          assert_equal expected.size, result.size
        end

        should "implement an :in condition" do
          total = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
          expected = total.select{|i| ["foo", "bar"].include?(i.name)}
          result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:conditions => {"name in" => ["foo", "bar"]}))
          assert_equal expected.size, result.size
        end<commit_msg>Adds a mongomapper Veneer Interface<commit_after>class Test::Unit::TestCase
  def self.veneer_should_implement_find
    context "implements find" do
      setup do
        Veneer(@klass).destroy_all
        (0..5).each do |i|
          Veneer(@klass).new(:order_field1 => i).save!
        end
      end

      teardown{ Veneer(@klass).destroy_all }

      should "impelement a find_all method" do
        result = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
        assert_kind_of Array, result
      end

      should "implement a find_first method" do
        result = Veneer(@klass).find_first(Veneer::Conditional.from_hash({}))
      end

      should "implement limit" do
        total = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
        assert_not_equal 3, total.size
        result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:limit => 3))
        assert_equal 3, result.size
      end

      should "implement order" do
        result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:order => "order_field1 asc"))
        raw = result.map{|i| i.order_field1 }.compact
        sorted = raw.sort
        assert_equal raw, sorted
      end

      should "implement asc and desc order as opposites" do
        result_asc  = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:order => "order_field1 asc")).map{|o| o.order_field1}
        result_desc = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:order => "order_field1 desc")).map{|o| o.order_field1}

        assert_equal result_asc, result_desc.reverse
      end

      should "implement order decending" do
        result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:order => "order_field1 desc"))
        raw = result.map{|i| i.order_field1 }.compact
        sorted = raw.sort.reverse
        assert_equal raw, sorted
      end

      should "implement order ascending" do
        result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:order => "order_field1 asc"))
        raw = result.map{|i| i.order_field1}.compact
        sorted = raw.sort
        assert_equal raw, sorted
      end

      should "impelment offset" do
        total = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
        result = Veneer(@klass).find_many(Veneer::Conditional.from_hash({:offset => 2, :limit => 2}))

        assert_equal((total[2..3]), result)
      end

      context "conditions" do
        setup do
          Veneer(@klass).new(:name => "bar").save
          Veneer(@klass).new(:name => "foo").save
          Veneer(@klass).new(:name => "foobar").save
        end

        should "implement basic conditions" do
          total = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
          result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:conditions => {:name => "foo"}))
          assert_equal 1, result.size
        end

        should "implement :not conditions" do
          Veneer(@klass).all(:conditions => {:name => nil}).map(&:destroy)
          total = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
          result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:conditions => {"name not" => "bar"}))
          assert_equal((total.size - 1), result.size)
        end

        should "implement gt conditions" do
          total = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
          expected = total.select{|i| !i.order_field1.nil? && i.order_field1 > 3}
          result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:conditions => {"order_field1 gt" => 3}))
          assert_equal expected.size, result.size
        end

        should "implement gte conditions" do
          total = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
          expected = total.select{|i| !i.order_field1.nil? && i.order_field1 >= 3}.map{|i| i.order_field1}
          result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:conditions => {"order_field1 gte" => 3})).map{|o| o.order_field1}
          assert_equal expected, result
        end

        should "implement :lt condition" do
          result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:conditions => {"order_field1 lt" => 3}))
          assert_equal 3, result.size
        end

        should "implement a lte condition" do
          total     = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
          expected  = total.select{|i| !i.order_field1.nil? && i.order_field1 <= 3}
          result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:conditions => {"order_field1 lte" => 3}))
          assert_equal expected.size, result.size
        end

        should "implement an :in condition" do
          total = Veneer(@klass).find_many(Veneer::Conditional.from_hash({}))
          expected = total.select{|i| ["foo", "bar"].include?(i.name)}
          result = Veneer(@klass).find_many(Veneer::Conditional.from_hash(:conditions => {"name in" => ["foo", "bar"]}))
          assert_equal expected.size, result.size
        end
{'fraction_non_alphanumeric': 0.13861877356618377, 'fraction_numerical': 0.008235761063703115, 'mean_word_length': 2.952549019607843, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, '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': '4427034', 'n_tokens_mistral': 3204, 'n_tokens_neox': 3194, 'n_words': 595}