<commit_before>require 'spec_helper'

describe Indicators::Data do

	describe ".new" do
		context "should raise an exception if parameter" do

		  it "is nil or empty" do
		  	expect { Indicators::Data.new(nil) }.to raise_error('There is no data to work on.')
		  	expect { Indicators::Data.new('') }.to raise_error('There is no data to work on.')
		  end
		  it "is not an array" do
		  	expect { Indicators::Data.new('some string') }.to raise_error(Indicators::Data::DataException, /Alien data. Given data must be an array/)
		  end
		end

		context "should not raise an exception if parameter" do

			it "is an array" do
				expect { Indicators::Data.new([1, 2, 3]) }.not_to raise_error
			end
			it "is a hash" do
				expect { 
                                    arr = Array.new(100).each_with_index.map { |x,i| {:date=>(Date.today+i).to_s,:open=>(2000+rand(500)*(-1)**[0,1].sample),:high=>(2500+rand(500)*(-1)**[0,1].sample), :low=>(1500+rand(500)*(-1)**[0,1].sample), :close=>(2000+rand(500)*(-1)**[0,1].sample), :volume=>"9286500", :adj_close=>2000+rand(500)*(-1)**[0,1].sample} }
                                    Indicators::Data.new arr
                                }.not_to raise_error
			end

		end
	end

	describe ".calc" do
		before :all do
                        arr = Array.new(100).each_with_index.map { |x,i| {:date=>(Date.today+i).to_s,:open=>(2000+rand(500)*(-1)**[0,1].sample),:high=>(2500+rand(500)*(-1)**[0,1].sample), :low=>(1500+rand(500)*(-1)**[0,1].sample), :close=>(2000+rand(500)*(-1)**[0,1].sample), :volume=>"9286500", :adj_close=>2000+rand(500)*(-1)**[0,1].sample} }
			@my_data = Indicators::Data.new arr
		end

		context "should raise an exception if parameter" do
			it "is not a hash" do
				expect { @my_data.calc('some string') }.to raise_error('Given parameters have to be a hash.')
			end
			it ":type is invalid" do
				expect { @my_data.calc(:type => :invalid_type, :params => 5) }.to raise_error(Indicators::Data::DataException, /Invalid indicator type specified/)
			end
		end

		context "should not raise an exception if parameter" do
			it ":type is not specified (should default to :sma)" do
				expect { @my_data.calc(:params => 5) }.not_to raise_error
				# Can't get this test to work for some reason.
				# @my_data.calc(:params => 5).abbr.downcase.to_sym should eq(:sma)
			end
			it "good SMA params are specified" do
				expect { @my_data.calc(:type => :sma, :params => 5) }.not_to raise_error
			end<commit_msg>rewrite spec little bit<commit_after>require 'spec_helper'

describe Indicators::Data do

	describe ".new" do
		context "should raise an exception if parameter" do

		  it "is nil or empty" do
		  	expect { Indicators::Data.new(nil) }.to raise_error('There is no data to work on.')
		  	expect { Indicators::Data.new('') }.to raise_error('There is no data to work on.')
		  end
		  it "is not an array" do
		  	expect { Indicators::Data.new('some string') }.to raise_error(Indicators::Data::DataException, /Alien data. Given data must be an array/)
		  end
		end

		context "should not raise an exception if parameter" do

			it "is an array" do
				expect { Indicators::Data.new([1, 2, 3]) }.not_to raise_error
			end
			it "is a hash" do
                                expect { Indicators::Data.new([{:date => '2012-08-01', :open => 2000, :high=>2000, :low=>2000, :close=>2000, :volume=>20000}]) }.not_to raise_error
			end

		end
	end

	describe ".calc" do
		before :all do
                        arr = Array.new(100).each_with_index.map do |x,i|
                            {
                                :date=>(Date.today+i).to_s,
                                :open=>(2000+rand(500)*(-1)**[0,1].sample),
                                :high=>(2500+rand(500)*(-1)**[0,1].sample), 
                                :low=>(1500+rand(500)*(-1)**[0,1].sample), 
                                :close=>(2000+rand(500)*(-1)**[0,1].sample), 
                                :volume=>"9286500", 
                                :adj_close=>2000+rand(500)*(-1)**[0,1].sample
                            } 
                        end
			@my_data = Indicators::Data.new arr
		end

		context "should raise an exception if parameter" do
			it "is not a hash" do
				expect { @my_data.calc('some string') }.to raise_error('Given parameters have to be a hash.')
			end
			it ":type is invalid" do
				expect { @my_data.calc(:type => :invalid_type, :params => 5) }.to raise_error(Indicators::Data::DataException, /Invalid indicator type specified/)
			end
		end

		context "should not raise an exception if parameter" do
			it ":type is not specified (should default to :sma)" do
				expect { @my_data.calc(:params => 5) }.not_to raise_error
				# Can't get this test to work for some reason.
				# @my_data.calc(:params => 5).abbr.downcase.to_sym should eq(:sma)
			end
			it "good SMA params are specified" do
				expect { @my_data.calc(:type => :sma, :params => 5) }.not_to raise_error
			end
{'fraction_non_alphanumeric': 0.15683511173746728, 'fraction_numerical': 0.04489631568351117, 'mean_word_length': 2.647577092511013, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4778282', 'n_tokens_mistral': 1952, 'n_tokens_neox': 1618, 'n_words': 446}