OSDN Git Service

move parenthesis into create_complex_number
authorTomohiro Nishimura <tomohiro68@gmail.com>
Sun, 21 Mar 2010 17:17:57 +0000 (02:17 +0900)
committerTomohiro Nishimura <tomohiro68@gmail.com>
Sun, 21 Mar 2010 17:17:57 +0000 (02:17 +0900)
lib/mint/generator/complex_number_arithmetic.rb
spec/generator/complex_number_arithmetic_spec.rb

index 5234fe6..afdc9cb 100644 (file)
@@ -39,12 +39,10 @@ module Mint::Generator
         if options[:fractional_mode]
           create_fractional_complex_number
         else
-          "(#{create_complex_number})"
+          create_complex_number
         end
-      return "#{result}^2"if options[:term_number] == 1
-      if last_operator == '/'
-        return conjugate_complex(last_operand)
-      end
+      return "#{result}^2" if options[:term_number] == 1
+      return conjugate_complex(last_operand) if last_operator == '/'
       result
     end
 
@@ -53,13 +51,13 @@ module Mint::Generator
       imaginary_part =  create_integer(options[:min], options[:max], false)
       return (2 + rand(8)).to_s if [real_part, imaginary_part].include? 0
       operator =  %w[ + - ].sample
-      "#{real_part} #{operator} #{imaginary_part.to_s.sub('1', '')}%i"
+      "(#{real_part} #{operator} #{imaginary_part.to_s.sub('1', '')}%i)"
     end
 
     def create_fractional_complex_number
       numerator_part = 1 + rand(9)
       denominator_part = create_complex_number
-      "#{numerator_part} / (#{denominator_part})"
+      "#{numerator_part} / #{denominator_part}"
     end
 
     def conjugate_complex(expression)
index 191f593..8c7b5ae 100644 (file)
@@ -26,14 +26,14 @@ module Mint::Generator
         settings = @defaults.merge(:max => 1)
         subject.__send__(:options=, settings)
         result = subject.__send__(:create_complex_number)
-        result.should match(/\A1 [\-+] %i\z/)
+        result.should match(/\A\(1 [\-+] %i\)\z/)
       end
 
       it 'general' do
         settings = @defaults.merge(:min => 2, :max => 9)
         subject.__send__(:options=, settings)
         result = subject.__send__(:create_complex_number)
-        result.should match(/\A\d [\-+] \d%i\z/)
+        result.should match(/\A\(\d [\-+] \d%i\)\z/)
       end
 
       it 'conjugate complex' do