<commit_before>require "spec_helper"

describe Metadata do

  it "is a hash" do
    expect(Metadata.new).to be_kind_of(Hash)
  end

  context 'instance methods' do
    let(:m){ Metadata.new(h) }

    describe "[]" do
      let(:key){h.keys.first}

      it "retrieves with a string key" do
        expect(m[key.to_s]).to eq h[key]
      end

      it "retrieves with a symbol key" do
        expect(m[key.to_sym]).to eq h[key]
      end
    end

    describe "[]=" do

      it 'sets with a string key' do
        m["a"] = 2
        expect(m[:a]).to eq 2
      end

      it 'sets with a symbol key' do
        m[:b] = 2
        expect(m["b"]).to eq 2
      end

    end

    describe "valid_key?" do

      it "is true for keys that aren't methods" do
        expect(m.valid_key?(:b)).to eq true
      end

      it "is false for existing methods" do
        expect(m.valid_key?(:to_hash)).to eq false
      end
    end

    describe "to_hash" do

      it "converts to a hash" do
        expect(m.to_hash).to_not be_kind_of Metadata
      end

      it "converts arrays" do

      end

    end

    describe "to_ary or to_a" do

      it "converts the hash to an array" do
        expect(m.to_a).to eq m.to_hash.to_a
      end

    end

    describe "initialize" do

      it "copies hash contents" do
        expect(Metadata.new(h)).to eq h
      end

      it "returns the argument" do
        m = Metadata.new
        expect(Metadata.new(m)).to eq m
      end
<commit_msg>add spec for checking conversion of arrays<commit_after>require "spec_helper"

describe Metadata do

  it "is a hash" do
    expect(Metadata.new).to be_kind_of(Hash)
  end

  context 'instance methods' do
    let(:m){ Metadata.new(h) }

    describe "[]" do
      let(:key){h.keys.first}

      it "retrieves with a string key" do
        expect(m[key.to_s]).to eq h[key]
      end

      it "retrieves with a symbol key" do
        expect(m[key.to_sym]).to eq h[key]
      end
    end

    describe "[]=" do

      it 'sets with a string key' do
        m["a"] = 2
        expect(m[:a]).to eq 2
      end

      it 'sets with a symbol key' do
        m[:b] = 2
        expect(m["b"]).to eq 2
      end

    end

    describe "valid_key?" do

      it "is true for keys that aren't methods" do
        expect(m.valid_key?(:b)).to eq true
      end

      it "is false for existing methods" do
        expect(m.valid_key?(:to_hash)).to eq false
      end
    end

    describe "to_hash" do

      it "converts to a hash" do
        expect(m.to_hash).to_not be_kind_of Metadata
      end

      it "converts arrays" do
        h = hash_with_array
        m = Metadata.new(h)
        expect(m.to_hash).to_not respond_to :array
        expect(m.to_hash[:array]).to be_a Array
      end

    end

    describe "to_ary or to_a" do

      it "converts the hash to an array" do
        expect(m.to_a).to eq m.to_hash.to_a
      end

    end

    describe "initialize" do

      it "copies hash contents" do
        expect(Metadata.new(h)).to eq h
      end

      it "returns the argument" do
        m = Metadata.new
        expect(Metadata.new(m)).to eq m
      end

{'fraction_non_alphanumeric': 0.10041440867070449, 'fraction_numerical': 0.002550207204335352, 'mean_word_length': 1.8762603116406966, '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': '7281550', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1047, 'n_words': 340}