Sha256: 051a97b3d58207f675a4d035f2e15634dc0db6da57a947a225a502ca11814570

Contents?: true

Size: 1.94 KB

Versions: 2

Compression:

Stored size: 1.94 KB

Contents

require 'spec_helper'
require 'middleman-blog-similar/algorithm/word_frequency'

describe 'Middleman::Blog::Similar::Algorithm::WordFrequency' do
  let(:app)     {
    middleman_app('test-app') {
      activate :similar, :algorithm => :word_frequency
    }
  }
  let(:article) { app.sitemap.find_resource_by_destination_path '/2014/05/10/article2.html' }
  let(:algorithm)  { article.similarity_algorithm }
  describe(:app) {
    describe(:similarity_algorithm) {
      subject { app.similarity_algorithm }
      it { should be ::Middleman::Blog::Similar::Algorithm::WordFrequency  }
    }
  }
  describe(:algorithm) {
    subject { algorithm }
    it { should be_a_kind_of ::Middleman::Blog::Similar::Algorithm::WordFrequency }
  }
  describe(:unigrams) {
    describe('length of keys') {
      subject { algorithm.unigrams.keys.length }
      it { should be 21089 }
    }
    describe('class') {
      subject { algorithm.unigrams }
      it { should be_a_kind_of Hash }
    }
  }
  describe(:similar_articles) {
    subject { algorithm.similar_articles.map(&:url) }
    it {
      should eq [
        "/2014/05/11/article3.html",
        "/2014/05/08/article0.html",
        "/2014/05/12/article4.html",
        "/2014/05/13/article5.html",
        "/2014/05/09/article1.html",
        "/2014/05/14/article6.html"
      ]
    }
  }
  describe(:tags) {
    subject { algorithm.tags }
    it { should eq ["fox", "quick", "dog", "brown", "the", "jump", "lazi", "over", "articl", "2"] }
  }
  describe(:word_freq) {
    subject { algorithm.word_freq }
    it {
      should eq({
       "brown" => 2,
       "dog" => 3,
       "fox" => 6,
       "jump" => 1,
       "lazi" => 1,
       "over" => 1,
       "quick" => 6,
       "the" => 2,
       "2" => 1,
       "articl" => 1
      })
    }
  }
  describe(:article) {
    describe(:similarity_algorithm) {
      subject { algorithm }
      it { should be_a_kind_of ::Middleman::Blog::Similar::Algorithm::WordFrequency }
    }
  }

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
middleman-blog-similar-1.1.1 spec/middleman-blog-similar/algorithm/word_frequency_spec.rb
middleman-blog-similar-1.1.0 spec/middleman-blog-similar/algorithm/word_frequency_spec.rb