<commit_before>require 'spec_helper'

describe "IntervalTree::Node" do

  describe '.new' do
    context 'given ([], [], [], [])' do
      it 'returns a Node object' do
        expect(IntervalTree::Node.new([], [], [], [])).to be_a(IntervalTree::Node)
      end
    end
  end

end

describe "IntervalTree::Tree" do

  describe '#center' do
    context 'given [(1...5),]' do
      it 'returns 3' do
        itvs = [(1...5),]
        t = IntervalTree::Tree.new([])
        expect(t.__send__(:center, itvs)).to be == 3

      end
    end

    context 'given [(1...5), (2...6)]' do
      it 'returns 3' do
        itvs = [(1...5), (2...6),]
        t = IntervalTree::Tree.new([])
        expect(t.__send__(:center, itvs)).to be == 3
      end
    end
  end

  describe '.new' do
    context 'given [(1...5)]' do
      it 'returns a Tree' do
        itvs = [(1...5)]
        expect(IntervalTree::Tree.new(itvs)).to be_an IntervalTree::Tree
      end
    end

    context 'given [(1...5),(2...6), (3...7)]' do
      it 'returns ret.top_node.x_centeran == 4' do
        itvs = [(1...5), (2...6), (3...7)]
        tree = IntervalTree::Tree.new(itvs)
        expect(tree.top_node.x_center).to be == 4
      end
    end

    context 'given [(1..5),(2..6), (3..7)]' do
      it 'returns ret.top_node.x_centeran == 4 ' do
        itvs = [(1..5), (2..6), (3..7)]
        tree = IntervalTree::Tree.new(itvs)
        expect(tree.top_node.x_center).to be == 4
      end
    end

    context 'with a custom range factory' do
      class ValueRange < Range
        attr_accessor :value
        def initialize(l, r, value = nil)
          super(l, r, true)
          @value = value
        end
      end
      context 'given [(1..5)] and a ValueRange factory block' do
        it 'constructs a range with a value' do
          itvs = [(1..5)]
          tree = IntervalTree::Tree.new(itvs) { |l, r| ValueRange.new(l, r, 15) }
          result = tree.search(2).first
          expect(result).to be_kind_of ValueRange
          expect(result.value).to be == 15
        end
      end
    end
  end

  describe '#search' do
    context 'given []' do
      it 'returns nil for all searches' do
        itvs = []
        IntervalTree::Tree.new(itvs).tap do |tree|
          expect(tree.search(5)).to be_nil
          expect(tree.search(1..2)).to be_nil
          expect(tree.search(1...2)).to be_nil
        end
      end
    end

    context 'given [(1...5)] a point query "3"' do
      it 'returns an array of intervals (1...5)]' do
        expect(IntervalTree::Tree.new([1...5]).search(3)).to be == [1...5]
      end

      it 'returns an empty array in the right end corner case' do
        expect(IntervalTree::Tree.new([1...5]).search(5)).to be == []
      end

      it 'returns the range in the left end corner case' do
        expect(IntervalTree::Tree.new([1...5]).search(1)).to be == [1...5]
      end
    end

    context 'given non-array full-closed "(1..4)" and a point query "3"' do
      it 'returns an array contains a half-open interval (1...5)]' do
        expect(IntervalTree::Tree.new(1..4).search(4)).to be == [1...5]
      end

      it 'returns an empty array in the right end corner case' do
        expect(IntervalTree::Tree.new(1..4).search(5)).to be == []
      end

      it 'returns the range in the left end corner case' do
        expect(IntervalTree::Tree.new(1..4).search(1)).to be == [1...5]
      end
    end

    context 'given [(1...5), (2...6)] and a point query "3"' do
      it 'returns [(1...5), (2...6)]' do
        itvs = [(1...5), (2...6),]
        results = IntervalTree::Tree.new(itvs).search(3)
        expect(results).to be == itvs
      end
    end

    context 'given [(0...8), (1...5), (2...6)] and a point query "3"' do
      it 'returns [(0...8), (1...5), (2...6)]' do
        itvs = [(0...8), (1...5), (2...6)]
        results = IntervalTree::Tree.new(itvs).search(3)
        expect(results).to be == itvs
      end
    end

    context 'given [(0...8), (1...5), (2...6)] and a query by (1...4)' do
      it 'returns [(0...8), (1...5), (2...6)]' do
        itvs = [(0...8), (1...5), (2...6)]
        results = IntervalTree::Tree.new(itvs).search(1...4)
        expect(results).to be == itvs
      end
    end

    context 'given [(1...3), (3...5)] and a query by 3' do
      it 'returns [(3...9)]' do
        results = IntervalTree::Tree.new([(1...3), (3...5)]).search(3...9)
        expect(results).to be == [(3...5)]
      end
    end

    context 'given [(1...3), (3...5), (4...8)] and a query by (3...5)' do
      it 'returns [(3...5), (4...8)]' do
        itvs = [(1...3), (3...5), (4...8)]
        results = IntervalTree::Tree.new(itvs).search(3...5)
        expect(results).to be == [(3...5), (4...8)]
      end
    end

    context 'given [(1...3), (3...5), (3...9), (4...8)] and a query by (3...5)' do
      it 'returns [(3...5), (3...9), (4...8)]' do
        itvs = [(1...3), (3...5), (3...9), (4...8)]
        results = IntervalTree::Tree.new(itvs).search(3...5)
        expect(results).to be == [(3...5), (3...9), (4...8)]
      end
    end
  end

end<commit_msg>correct typos in interval_tree_spec.rb<commit_after>require 'spec_helper'

describe "IntervalTree::Node" do

  describe '.new' do
    context 'given ([], [], [], [])' do
      it 'returns a Node object' do
        expect(IntervalTree::Node.new([], [], [], [])).to be_a(IntervalTree::Node)
      end
    end
  end

end

describe "IntervalTree::Tree" do

  describe '#center' do
    context 'given [(1...5),]' do
      it 'returns 3' do
        itvs = [(1...5),]
        t = IntervalTree::Tree.new([])
        expect(t.__send__(:center, itvs)).to be == 3

      end
    end

    context 'given [(1...5), (2...6)]' do
      it 'returns 3' do
        itvs = [(1...5), (2...6),]
        t = IntervalTree::Tree.new([])
        expect(t.__send__(:center, itvs)).to be == 3
      end
    end
  end

  describe '.new' do
    context 'given [(1...5)]' do
      it 'returns a Tree' do
        itvs = [(1...5)]
        expect(IntervalTree::Tree.new(itvs)).to be_an IntervalTree::Tree
      end
    end

    context 'given [(1...5),(2...6), (3...7)]' do
      it 'returns ret.top_node.x_centeran == 4' do
        itvs = [(1...5), (2...6), (3...7)]
        tree = IntervalTree::Tree.new(itvs)
        expect(tree.top_node.x_center).to be == 4
      end
    end

    context 'given [(1..5),(2..6), (3..7)]' do
      it 'returns ret.top_node.x_centeran == 4 ' do
        itvs = [(1..5), (2..6), (3..7)]
        tree = IntervalTree::Tree.new(itvs)
        expect(tree.top_node.x_center).to be == 4
      end
    end

    context 'with a custom range factory' do
      class ValueRange < Range
        attr_accessor :value
        def initialize(l, r, value = nil)
          super(l, r, true)
          @value = value
        end
      end
      context 'given [(1..5)] and a ValueRange factory block' do
        it 'constructs a range with a value' do
          itvs = [(1..5)]
          tree = IntervalTree::Tree.new(itvs) { |l, r| ValueRange.new(l, r, 15) }
          result = tree.search(2).first
          expect(result).to be_kind_of ValueRange
          expect(result.value).to be == 15
        end
      end
    end
  end

  describe '#search' do
    context 'given []' do
      it 'returns nil for all searches' do
        itvs = []
        IntervalTree::Tree.new(itvs).tap do |tree|
          expect(tree.search(5)).to be_nil
          expect(tree.search(1..2)).to be_nil
          expect(tree.search(1...2)).to be_nil
        end
      end
    end

    context 'given [(1...5)] and a point query "3"' do
      it 'returns an array of intervals (1...5)]' do
        expect(IntervalTree::Tree.new([1...5]).search(3)).to be == [1...5]
      end

      it 'returns an empty array in the right end corner case' do
        expect(IntervalTree::Tree.new([1...5]).search(5)).to be == []
      end

      it 'returns the range in the left end corner case' do
        expect(IntervalTree::Tree.new([1...5]).search(1)).to be == [1...5]
      end
    end

    context 'given non-array full-closed "(1..4)" and a point query "3"' do
      it 'returns an array contains a half-open interval (1...5)]' do
        expect(IntervalTree::Tree.new(1..4).search(4)).to be == [1...5]
      end

      it 'returns an empty array in the right end corner case' do
        expect(IntervalTree::Tree.new(1..4).search(5)).to be == []
      end

      it 'returns the range in the left end corner case' do
        expect(IntervalTree::Tree.new(1..4).search(1)).to be == [1...5]
      end
    end

    context 'given [(1...5), (2...6)] and a point query "3"' do
      it 'returns [(1...5), (2...6)]' do
        itvs = [(1...5), (2...6),]
        results = IntervalTree::Tree.new(itvs).search(3)
        expect(results).to be == itvs
      end
    end

    context 'given [(0...8), (1...5), (2...6)] and a point query "3"' do
      it 'returns [(0...8), (1...5), (2...6)]' do
        itvs = [(0...8), (1...5), (2...6)]
        results = IntervalTree::Tree.new(itvs).search(3)
        expect(results).to be == itvs
      end
    end

    context 'given [(0...8), (1...5), (2...6)] and a query by (1...4)' do
      it 'returns [(0...8), (1...5), (2...6)]' do
        itvs = [(0...8), (1...5), (2...6)]
        results = IntervalTree::Tree.new(itvs).search(1...4)
        expect(results).to be == itvs
      end
    end

    context 'given [(1...3), (3...5)] and a query by (3...9)' do
      it 'returns [(3...5)]' do
        results = IntervalTree::Tree.new([(1...3), (3...5)]).search(3...9)
        expect(results).to be == [(3...5)]
      end
    end

    context 'given [(1...3), (3...5), (4...8)] and a query by (3...5)' do
      it 'returns [(3...5), (4...8)]' do
        itvs = [(1...3), (3...5), (4...8)]
        results = IntervalTree::Tree.new(itvs).search(3...5)
        expect(results).to be == [(3...5), (4...8)]
      end
    end

    context 'given [(1...3), (3...5), (3...9), (4...8)] and a query by (3...5)' do
      it 'returns [(3...5), (3...9), (4...8)]' do
        itvs = [(1...3), (3...5), (3...9), (4...8)]
        results = IntervalTree::Tree.new(itvs).search(3...5)
        expect(results).to be == [(3...5), (3...9), (4...8)]
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.2075563799668066, 'fraction_numerical': 0.04403006931563019, 'mean_word_length': 1.8400332686443028, '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': '1330725', 'n_tokens_mistral': 3748, 'n_tokens_neox': 3558, 'n_words': 983}