<commit_before>require 'spec_helper'

describe TechnicalAnalysis::LastMaximumDisruption do
  it 'should get signal for each entry point' do
    subject.should_receive(:range).and_return([1,2,3,4])
    subject.should_receive(:entry_point?).exactly(4).times.and_return(true, false, true, false)
    subject.should_receive(:signal).exactly(2).times.and_return(1)

    subject.run_setup.should == [1, 1]
  end

  context '#candle' do
    subject { TechnicalAnalysis::LastMaximumDisruption.new candle_array: [:one_item_only] }
    it 'Should return nil when index does not match item' do
      subject.candle(1).should be_nil
    end

    it 'Should return the item if no attribute name given' do
      subject.candle(0).should == :one_item_only
    end

    context '' do
      let(:candle) do
        cdl = double(:candle)
        cdl.should_receive(:my_fancy_attribute)
          .once
          .and_return(:value)
        cdl
      end
      subject { TechnicalAnalysis::LastMaximumDisruption.new candle_array: [candle] }

      it 'Should return the attribute value for the given attribute name' do
        subject.candle(0, :my_fancy_attribute).should == :value
      end
    end
  end

  context '#trade?' do
    before(:each) do
      subject.should_receive(:candle)
        .once
        .with(-1, :high)
        .and_return(200)
    end

    it{ subject.trade?(100).should be_false }
    it{ subject.trade?(300).should be_true }
  end
end<commit_msg>Added test for #stop_loss<commit_after>require 'spec_helper'

describe TechnicalAnalysis::LastMaximumDisruption do
  it 'should get signal for each entry point' do
    subject.should_receive(:range).and_return([1,2,3,4])
    subject.should_receive(:entry_point?).exactly(4).times.and_return(true, false, true, false)
    subject.should_receive(:signal).exactly(2).times.and_return(1)

    subject.run_setup.should == [1, 1]
  end

  context '#candle' do
    subject { TechnicalAnalysis::LastMaximumDisruption.new candle_array: [:one_item_only] }
    it 'Should return nil when index does not match item' do
      subject.candle(1).should be_nil
    end

    it 'Should return the item if no attribute name given' do
      subject.candle(0).should == :one_item_only
    end

    context '' do
      let(:candle) do
        cdl = double(:candle)
        cdl.should_receive(:my_fancy_attribute)
          .once
          .and_return(:value)
        cdl
      end
      subject { TechnicalAnalysis::LastMaximumDisruption.new candle_array: [candle] }

      it 'Should return the attribute value for the given attribute name' do
        subject.candle(0, :my_fancy_attribute).should == :value
      end
    end
  end

  context '#trade?' do
    before(:each) do
      subject.should_receive(:candle)
        .once
        .with(-1, :high)
        .and_return(200)
    end

    it{ subject.trade?(100).should be_false }
    it{ subject.trade?(300).should be_true }
  end

  context '#stop_loss' do
    it 'Should get the rounded by 2 value of low' do
      low = double(:low)
      low.should_receive(:round).once.with(2).and_return(:rounded_by_2)

      subject.should_receive(:candle)
        .once
        .with(:idx, :low)
        .and_return(low)

      subject.stop_loss(:idx).should == :rounded_by_2
    end
  end
end
{'fraction_non_alphanumeric': 0.10690287110568113, 'fraction_numerical': 0.014660965180207697, 'mean_word_length': 2.998778998778999, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1692101', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1033, 'n_words': 250}