Browse files

+ more specs, + rake stats

  • Loading branch information...
1 parent 2e628bd commit f865acdd894b7bcc226e53183ef210167008f784 @floere committed Dec 1, 2011
View
2 server/lib/picky/query/allocation.rb
@@ -70,7 +70,7 @@ def <=> other_allocation
# Transform the allocation into result form.
#
def to_result
- [self.result_identifier, self.score, self.count, @combinations.to_result, self.ids] if self.count > 0
+ [self.result_identifier, self.score, self.count, @combinations.to_result, self.ids] if self.count && self.count > 0
end
# Json representation of this allocation.
View
12 server/lib/picky/query/allocations.rb
@@ -103,12 +103,6 @@ def to_a
@allocations
end
- # Simply inspects the internal allocations.
- #
- def to_s
- @allocations.inspect
- end
-
# Allocations for results are in the form:
# [
# allocation1.to_result,
@@ -120,6 +114,12 @@ def to_result
@allocations.map(&:to_result).compact
end
+ # Simply inspects the internal allocations.
+ #
+ def to_s
+ to_result.inspect
+ end
+
end
end
View
34 server/spec/functional/terminate_early_spec.rb
@@ -49,6 +49,17 @@
try.search('hello', 9, 22).ids.should == [2, 1]
try.search('hello', 9, 25).ids.should == []
+ try.search('hello', 9).to_hash[:allocations].size.should == 2
+ try.search('hello', 9, 4).to_hash[:allocations].size.should == 3
+ try.search('hello', 9, 7).to_hash[:allocations].size.should == 3
+ try.search('hello', 9, 10).to_hash[:allocations].size.should == 4
+ try.search('hello', 9, 13).to_hash[:allocations].size.should == 4
+ try.search('hello', 9, 16).to_hash[:allocations].size.should == 4
+ try.search('hello', 9, 19).to_hash[:allocations].size.should == 4
+ try.search('hello', 9, 22).to_hash[:allocations].size.should == 4
+ try.search('hello', 9, 25).to_hash[:allocations].size.should == 4
+
+
try = Picky::Search.new index do
terminate_early 0
end
@@ -68,6 +79,12 @@
try.search('hello', 13, 12).ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]
try.search('hello', 13, 16).ids.should == [2, 1, 6, 5, 4, 3, 2, 1]
+ try.search('hello', 13).to_hash[:allocations].size.should == 3
+ try.search('hello', 13, 4).to_hash[:allocations].size.should == 3
+ try.search('hello', 13, 8).to_hash[:allocations].size.should == 4
+ try.search('hello', 13, 12).to_hash[:allocations].size.should == 4
+ try.search('hello', 13, 16).to_hash[:allocations].size.should == 4
+
try = Picky::Search.new index do
terminate_early with_extra_allocations: 2
end
@@ -78,6 +95,23 @@
end
try.search('hello').ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5]
+ try = Picky::Search.new index do
+ terminate_early 1
+ end
+ try.search('hello', 1).ids.should == [6]
+ try.search('hello', 1, 4).ids.should == [2]
+ try.search('hello', 1, 8).ids.should == [4]
+ try.search('hello', 1, 12).ids.should == [6]
+ try.search('hello', 1, 16).ids.should == [2]
+
+ try.search('hello', 1).to_hash[:allocations].size.should == 2
+ try.search('hello', 1, 4).to_hash[:allocations].size.should == 2
+ try.search('hello', 1, 8).to_hash[:allocations].size.should == 2
+ try.search('hello', 1, 12).to_hash[:allocations].size.should == 3
+ try.search('hello', 1, 16).to_hash[:allocations].size.should == 3
+ try.search('hello', 1, 20).to_hash[:allocations].size.should == 4
+ try.search('hello', 1, 24).to_hash[:allocations].size.should == 4
+
GC.start
try_slow = Picky::Search.new index
View
8 server/spec/lib/query/allocations_spec.rb
@@ -362,12 +362,12 @@
describe "to_s" do
before(:each) do
- @internal_allocations = mock :internal_allocations
- @allocations = described_class.new @internal_allocations
+ @allocation = stub :allocation, :to_result => :some_result
+ @no_result_allocation = stub :no_results, :to_result => nil
+ @allocations = described_class.new [@allocation, @no_result_allocation, @allocation]
end
it "should delegate to the internal allocations array" do
- @internal_allocations.should_receive(:inspect).once
- @allocations.to_s
+ @allocations.to_s.should == "[:some_result, :some_result]"
end
end
View
2 server/tasks/stats.rake
@@ -2,7 +2,7 @@
#
desc "Pedestrian CLOC statistics."
task :stats do
- %w|lib spec test_project|.each do |dir|
+ %w|lib spec test_project test_project_sinatra|.each do |dir|
original_dir = dir
dir = "#{dir}/*.rb"
dirs = 5.times.inject([dir]) do |dirs, _|

0 comments on commit f865acd

Please sign in to comment.