spec/lib/query/weights_spec.rb in picky-1.2.4 vs spec/lib/query/weights_spec.rb in picky-1.3.0

- old
+ new

@@ -1,47 +1,70 @@ require 'spec_helper' describe Query::Weights do - before(:each) do - @weights = Query::Weights.new [:test1, :test2] => 6, - [:test1] => 5, - [:test3] => 3, - [:test3, :test2] => 4, - [:test1, :test4] => 5, - [:test4, :test1] => 5, - [:test4, :test1, :test2] => 4, - [:test1, :test4, :test2] => 4, - [:test4, :test5] => 3, - [:test5, :test1] => 2, - [:test1, :test5] => 2, - [:test3, :test1] => 2, - [:test1, :test3] => 2 - end + context 'with weights' do + before(:each) do + @weights = Query::Weights.new [:test1, :test2] => 6, + [:test1] => 5, + [:test3] => 3, + [:test3, :test2] => 4, + [:test1, :test4] => 5, + [:test4, :test1] => 5, + [:test4, :test1, :test2] => 4, + [:test1, :test4, :test2] => 4, + [:test4, :test5] => 3, + [:test5, :test1] => 2, + [:test1, :test5] => 2, + [:test3, :test1] => 2, + [:test1, :test3] => 2 + end - describe "weight_for" do - it "should return zero if there is no specific weight" do - @weights.weight_for([:not_a_specific_allocation]).should be_zero + describe "weight_for" do + it "should return zero if there is no specific weight" do + @weights.weight_for([:not_a_specific_allocation]).should be_zero + end end - end - def self.it_should_return_a_specific_weight_for(allocation, weight) - it "should return weight #{weight} for #{allocation.inspect}" do - @weights.weight_for(allocation).should == weight + def self.it_should_return_a_specific_weight_for(allocation, weight) + it "should return weight #{weight} for #{allocation.inspect}" do + @weights.weight_for(allocation).should == weight + end end - end - it_should_return_a_specific_weight_for [:test1, :test2], 6 - it_should_return_a_specific_weight_for [:test1], 5 - it_should_return_a_specific_weight_for [:test1, :test3], 2 - it_should_return_a_specific_weight_for [:test3], 3 - it_should_return_a_specific_weight_for [:test3, :test2], 4 - it_should_return_a_specific_weight_for [:test1, :test4], 5 - it_should_return_a_specific_weight_for [:test4, :test1], 5 - it_should_return_a_specific_weight_for [:test4, :test1, :test2], 4 - it_should_return_a_specific_weight_for [:test1, :test4, :test2], 4 - it_should_return_a_specific_weight_for [:test4, :test5], 3 - it_should_return_a_specific_weight_for [:test5, :test1], 2 - it_should_return_a_specific_weight_for [:test1, :test5], 2 - it_should_return_a_specific_weight_for [:test3, :test1], 2 + it_should_return_a_specific_weight_for [:test1, :test2], 6 + it_should_return_a_specific_weight_for [:test1], 5 + it_should_return_a_specific_weight_for [:test1, :test3], 2 + it_should_return_a_specific_weight_for [:test3], 3 + it_should_return_a_specific_weight_for [:test3, :test2], 4 + it_should_return_a_specific_weight_for [:test1, :test4], 5 + it_should_return_a_specific_weight_for [:test4, :test1], 5 + it_should_return_a_specific_weight_for [:test4, :test1, :test2], 4 + it_should_return_a_specific_weight_for [:test1, :test4, :test2], 4 + it_should_return_a_specific_weight_for [:test4, :test5], 3 + it_should_return_a_specific_weight_for [:test5, :test1], 2 + it_should_return_a_specific_weight_for [:test1, :test5], 2 + it_should_return_a_specific_weight_for [:test3, :test1], 2 + + describe 'to_s' do + it 'is correct' do + @weights.to_s.should == "{[:test1, :test2]=>6, [:test1]=>5, [:test3]=>3, [:test3, :test2]=>4, [:test1, :test4]=>5, [:test4, :test1]=>5, [:test4, :test1, :test2]=>4, [:test1, :test4, :test2]=>4, [:test4, :test5]=>3, [:test5, :test1]=>2, [:test1, :test5]=>2, [:test3, :test1]=>2, [:test1, :test3]=>2}" + end + end + describe 'empty?' do + it 'is correct' do + @weights.empty?.should == false + end + end + end + context 'without weights' do + before(:each) do + @weights = Query::Weights.new + end + describe 'empty?' do + it 'is correct' do + @weights.empty?.should == true + end + end + end end \ No newline at end of file