spec/specset_spec.rb in marcspec-0.8.1 vs spec/specset_spec.rb in marcspec-1.0.0

- old
+ new

@@ -1,7 +1,9 @@ require 'spec_helper' +positive = lambda{|x| x > 0} + module A module B def self.titleUp doc, r, codes=nil title = r['245'] if codes @@ -44,28 +46,49 @@ ["260", "a"], ["651", "a"], ["651", "z"], ] }, - {:solrField=>'title', :specs=>[['245']]}, { + :solrField=>'title', + :specs=>[['245']] + }, + { :solrField => 'titleA', :specs => [['245', 'a']] + }, + { + :solrField => 'constantField', + :constantValue => ['A', 'B'] } ] + + @ss = MARCSpec::SpecSet.new + @ss.buildSpecsFromList(@speclist) + @h = @ss.hash_from_marc @one + end - it "should build from a list" do - ss = MARCSpec::SpecSet.new - ss.buildSpecsFromList(@speclist) - ss.solrfieldspecs.size.should.equal 3 - h = ss.hash_from_marc @one - h['places'].sort.should.equal @places.sort - h['title'].should.equal @title - h['titleA'].should.equal @titleA + it "should get all the specs" do + @ss.solrfieldspecs.size.should.equal 4 end + it "gets the places field" do + @h['places'].sort.should.equal @places.sort + end + + correct = { + 'title' => @title, + 'titleA' => @titleA, + 'constantField' => ['A', 'B'] + } + correct.each do |k,v| + it "gets correct value for #{k}" do + @h[k].should.equal v + end + end + it "allows customs that reference previous work" do @speclist << {:solrField=>'titleSort', :module=>A::B, :functionSymbol=>:sortable, :functionArgs=>['title']} ss = MARCSpec::SpecSet.new ss.buildSpecsFromList(@speclist) h = ss.hash_from_marc @one @@ -94,10 +117,52 @@ h['one'].should.equal [1] h['two'].should.equal [2] h['letters'].should.equal ['a', 'b'] end end - + + + +describe "Specset Benchmarking" do + before do + @reader = MARC4J4R::Reader.new("#{DIR}/data/batch.dat") + @speclist = [ + { + :solrField=>'title', + :specs=>[['245']] + }, + { + :solrField=> "places", + :specs => [ + ["260", "a"], + ["651", "a"], + ["651", "z"], + ] + }, + { + :solrField => 'titleA', + :specs => [['245', 'a']] + } + ] + + @ss = MARCSpec::SpecSet.new + @ss.buildSpecsFromList(@speclist) + end + + it "should benchmark" do + @reader.each do |r| + h = @ss.hash_from_marc(r, true) + end + @ss.solrfieldspecs.each do |sfs| + @ss.benchmarks[sfs.solrField].real.should.be positive + end + + # @ss.benchmarks.each do |k,v| + # puts "%-10s %s" % [k + ':', v.to_s] + # end + end +end + \ No newline at end of file