OSDN Git Service

add sort trick for expansion generator
authorTomohiro Nishimura <tomohiro68@gmail.com>
Mon, 8 Mar 2010 10:26:53 +0000 (19:26 +0900)
committerTomohiro Nishimura <tomohiro68@gmail.com>
Mon, 8 Mar 2010 10:26:53 +0000 (19:26 +0900)
lib/mint/generator/high_order_expression_base.rb
spec/generator/high_order_expression_base_spec.rb

index ff6a000..f565d9b 100644 (file)
@@ -136,7 +136,7 @@ module Mint::Generator
       order = create_integer(options[:order_min], options[:order_max], false)
       x = options[:x].sample
       order.times{ result << single(factor(options), factor(options), x) }
-      result.join("")
+      result.sort_by(&:length).reverse.join("")
     end
   end
 end
index bd03c05..923e145 100644 (file)
@@ -114,11 +114,20 @@ module Mint::Generator
             subject.stub(:single => @single)
             subject.instance_variable_set(:@options, :x => ['x'])
           end
-
           it do
             expression = subject.__send__(:expansion)
             expression.should == "#{@single}#{@single}"
           end
+          it do
+            subject.should_receive(:single).and_return('x', @single)
+            expression = subject.__send__(:expansion)
+            expression.should == "#{@single}x"
+          end
+          it do
+            subject.should_receive(:single).and_return(@single, 'x')
+            expression = subject.__send__(:expansion)
+            expression.should == "#{@single}x"
+          end
         end
       end
     end