OSDN Git Service

add complex_number_arithmetic solver
authorTomohiro Nishimura <tomohiro68@gmail.com>
Mon, 22 Feb 2010 01:55:09 +0000 (10:55 +0900)
committerTomohiro Nishimura <tomohiro68@gmail.com>
Mon, 22 Feb 2010 01:55:09 +0000 (10:55 +0900)
lib/mint/solver/maxima/complex_number_arithmetic.rb [new file with mode: 0644]
spec/solver/maxima/complex_number_arithmetic_spec.rb [new file with mode: 0644]

diff --git a/lib/mint/solver/maxima/complex_number_arithmetic.rb b/lib/mint/solver/maxima/complex_number_arithmetic.rb
new file mode 100644 (file)
index 0000000..3d32062
--- /dev/null
@@ -0,0 +1,12 @@
+# -*- coding: utf-8 -*-
+
+module Mint::Solver::Maxima
+
+  class ComplexNumberArithmetic < Base
+    private
+    def solve_problem(problem)
+      ratsimp(rectform(problem))
+    end
+  end
+end
+
diff --git a/spec/solver/maxima/complex_number_arithmetic_spec.rb b/spec/solver/maxima/complex_number_arithmetic_spec.rb
new file mode 100644 (file)
index 0000000..770db9d
--- /dev/null
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+
+require File.dirname(__FILE__) + '/../../spec_helper.rb'
+
+module Mint::Solver::Maxima
+
+  describe ComplexNumberArithmetic do
+
+    subject { ComplexNumberArithmetic.new }
+
+    [
+       ['(8 - 8 * %i) / (8 + 8 * %i)', '-%i'],
+       ['(7 - 2 * %i) / (7 + 2 * %i)', '-(28*%i-45)/53'],
+       ['(9 + 9 * %i) * (6 - 2 * %i)', '36*%i+72'],
+       ['(8 - 2 * %i) * (6 - 9 * %i)', '30-84*%i'],
+
+    ].each do |exp, ans|
+      it exp do
+        expression = Mint::Builder.build(exp)
+        result = subject.solve(expression)
+        answer = Mint::Builder.build(ans)
+        result.should == answer
+      end
+    end
+  end
+end
+