<commit_before># encoding: utf-8
require 'quandl/operation/qdformat'
require 'spec_helper'

describe Quandl::Operation::QDFormat do
  
  let(:full_code){ "SOURCE_CODE/DATASET_CODE" }
  let(:name){ 'name: Test dataset name' }
  let(:description){ 'description: Dataset description' }
  let(:headers){ 'headers: Date, value, high, low' }
  let(:data){ "2013-11-20,9.99470588235294,11.003235294117646,14.00164705882353\n2013-11-19,10.039388096885814,,14.09718770934256\n2013-11-18,10.03702588792184,11.040801329322205,14.148600982164867\n2013-11-16,10.019903902583621,10.99988541851354,14.186053161235304\n2013-11-15,9.98453953586862,10.922239168500502,\n2013-11-14,10.004508614940358,10.894612328250766,\n2013-11-13,,10.877309120435308,14.187437960548612\n2013-11-12,,10.838918617657301,14.22499294338536\n2013-11-11,9.965116185761039,10.827442115591547,14.178970907392053\n2013-11-09,9.881291973139637,10.924889094631869" }
  
  let(:output){
    %Q{
      ---
      #{full_code}
      #{name}
      #{description}
      #{headers}
      #{data}
      -
      - I am a comment.
      -
      #{full_code}
      #{name}
      #{description}
      #{headers}
      #{data}
      -----
    }
  }
  
  describe ".parse" do
    let(:collection){ Quandl::Operation::QDFormat.parse(output) }
    
    subject{ collection }
      
    its(:count){ should eq 2 }
    
    describe "#first" do
      subject{ collection.first }

      it{ should be_a Quandl::Operation::QDFormat }
      its(:source_code){ should eq 'SOURCE_CODE' }
      its(:code){ should eq 'DATASET_CODE' }
      its(:name){ should eq 'Test dataset name' }
      its(:description){ should eq 'Dataset description' }
      its(:column_names){ should eq ['Date', 'value', 'high', 'low'] }
      its(:data){ should eq data }
    end
  end
  
end<commit_msg>write failing spec for to_qdf<commit_after># encoding: utf-8
require 'quandl/operation/qdformat'
require 'spec_helper'

describe Quandl::Operation::QDFormat do
  
  let(:full_code){ "SOURCE_CODE/DATASET_CODE" }
  let(:name){ 'name: Test dataset name' }
  let(:description){ 'description: Dataset description' }
  let(:headers){ 'headers: Date, value, high, low' }
  let(:data){ "2013-11-20,9.99470588235294,11.003235294117646,14.00164705882353\n2013-11-19,10.039388096885814,,14.09718770934256\n2013-11-18,10.03702588792184,11.040801329322205,14.148600982164867\n2013-11-16,10.019903902583621,10.99988541851354,14.186053161235304\n2013-11-15,9.98453953586862,10.922239168500502,\n2013-11-14,10.004508614940358,10.894612328250766,\n2013-11-13,,10.877309120435308,14.187437960548612\n2013-11-12,,10.838918617657301,14.22499294338536\n2013-11-11,9.965116185761039,10.827442115591547,14.178970907392053\n2013-11-09,9.881291973139637,10.924889094631869" }
  
  let(:output){
    %Q{
      ---
      #{full_code}
      #{name}
      #{description}
      #{headers}
      #{data}
      -
      - I am a comment.
      -
      #{full_code}
      #{name}
      #{description}
      #{headers}
      #{data}
      -----
    }
  }
  let(:collection){ Quandl::Operation::QDFormat.parse(output) }
  
  describe ".parse" do
    
    subject{ collection }
      
    its(:count){ should eq 2 }
    
    describe "#first" do
      subject{ collection.first }

      it{ should be_a Quandl::Operation::QDFormat }
      its(:source_code){ should eq 'SOURCE_CODE' }
      its(:code){ should eq 'DATASET_CODE' }
      its(:name){ should eq 'Test dataset name' }
      its(:description){ should eq 'Dataset description' }
      its(:headers){ should eq ['Date', 'value', 'high', 'low'] }
      its(:data){ should eq data }
    end
  end
  
  describe "#to_qdf" do
    subject{ collection.first }
    its(:to_qdf){ should eq [full_code, name, description, headers, data].join("\n")}
    
    context "data Array" do
      let(:data){ [['2013-11-20',9.94,11.2],['2013-11-19',9.94,11.2],['2013-11-18',9.94,11.2]] }
      subject{ Quandl::Operation::QDFormat.new( full_code: "TEST/OIL", data: data ) }
      
      its(:to_qdf){ should eq ["TEST/OIL", data.collect(&:to_csv).join].join("\n") }
      
    end
  end
  
end
{'fraction_non_alphanumeric': 0.15867607690435628, 'fraction_numerical': 0.2433682161109759, 'mean_word_length': 3.391025641025641, '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': '5515105', 'n_tokens_mistral': 2149, 'n_tokens_neox': 1603, 'n_words': 231}