OSDN Git Service

fix complex_number_arithmetic with 0 bug
authorTomohiro Nishimura <tomohiro68@gmail.com>
Fri, 26 Mar 2010 09:37:18 +0000 (18:37 +0900)
committerTomohiro Nishimura <tomohiro68@gmail.com>
Fri, 26 Mar 2010 09:37:18 +0000 (18:37 +0900)
lib/mint/generator/complex_number_arithmetic.rb
spec/generator/complex_number_arithmetic_spec.rb

index 6991f03..2089d7e 100644 (file)
@@ -45,7 +45,7 @@ module Mint::Generator
       real_part      = create_integer(options[:min], options[:max], false)
       imaginary_part = create_integer(options[:min], options[:max], false)
       return create_integer(2, 9, false).to_s if [real_part, imaginary_part].include? 0
-      "(#{real_part} #{plus_or_minus} #{imaginary_part.to_s.sub('1', '')}%i)"
+      "(#{real_part} #{plus_or_minus} #{imaginary_part.to_s.sub(/\A1\z/, '')}%i)"
     end
 
     def plus_or_minus
index 8c7b5ae..2c95c19 100644 (file)
@@ -36,6 +36,13 @@ module Mint::Generator
         result.should match(/\A\(\d [\-+] \d%i\)\z/)
       end
 
+      it 'include 10' do
+        subject.stub(:create_integer).and_return(2, 10)
+        subject.stub(:plus_or_minus => '+')
+        result = subject.__send__(:create_complex_number)
+        result.should_not match(/\A\(2 \+ 0%i\)\z/)
+      end
+
       it 'conjugate complex' do
         settings = @defaults.merge(:max => 1)
         subject.__send__(:options=, settings)