<commit_before>require 'markovchain-storage-mongodb'
require 'mongo'

module Markovchain::Storage
  describe MongoDb do
    let(:mongo) { ::Mongo::Connection.new }
    let(:db) { 'markovchain_storage_mongodb_test' }
    let(:collection) { 'markovchain_storage_mongodb_test_storage' }

    before do
      mongo[db].drop_collection(collection)
      mongo[db].create_collection(collection)
    end

    let(:storage) do
      ::Markovchain::Storage::MongoDb.new(
        :mongo      => mongo,
        :db         => db,
        :collection => collection,
      )
    end

    describe '#tokens_after' do
      subject { storage.tokens_after(sequence) }
      let(:sequence) { 'foo' }

      context 'when no records matched' do
        it { should == {} }
      end

      context 'when a record matched' do
        before { storage.increment(sequence, token) }
        let(:token) { 'b' }
        it { should == {'b' => 1} }
      end

      context 'when many token seeded' do
        before do
          storage.increment(sequence, 'a')
          storage.increment(sequence, 'a')
          storage.increment(sequence, 'a')
          storage.increment(sequence, 'b')
          storage.increment(sequence, 'b')
          storage.increment(sequence, 'c')
        end
        it { should == {'a' => 3, 'b' => 2, 'c' => 1} }
      end
    end
  end
end<commit_msg>Add a spec.<commit_after>require 'markovchain-storage-mongodb'
require 'mongo'

module Markovchain::Storage
  describe MongoDb do
    let(:mongo) { ::Mongo::Connection.new }
    let(:db) { 'markovchain_storage_mongodb_test' }
    let(:collection) { 'markovchain_storage_mongodb_test_storage' }

    before do
      mongo[db].drop_collection(collection)
      mongo[db].create_collection(collection)
    end

    let(:storage) do
      ::Markovchain::Storage::MongoDb.new(
        :mongo      => mongo,
        :db         => db,
        :collection => collection,
      )
    end

    describe '#tokens_after' do
      subject { storage.tokens_after(sequence) }
      let(:sequence) { 'foo' }

      context 'when no records matched' do
        it { should == {} }
      end

      context 'when a record matched' do
        before { storage.increment(sequence, token) }
        let(:token) { 'b' }
        it { should == {'b' => 1} }
      end

      context 'when many token seeded' do
        before do
          storage.increment(sequence, 'a')
          storage.increment(sequence, 'a')
          storage.increment(sequence, 'a')
          storage.increment(sequence, 'b')
          storage.increment(sequence, 'b')
          storage.increment(sequence, 'c')
        end
        it { should == {'a' => 3, 'b' => 2, 'c' => 1} }
      end

      context 'sequence contains . (dot) specified' do
        let(:sequence) { 'f.o' }
        before do
          storage.increment(sequence, 'a')
        end
        it { should == {'a' => 1} }
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12978142076502733, 'fraction_numerical': 0.0030737704918032786, 'mean_word_length': 2.2151481888035125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '2756982', 'n_tokens_mistral': 922, 'n_tokens_neox': 887, 'n_words': 209}