OSDN Git Service

refactoring decimal method
[mint/mint-lib.git] / spec / builder_spec.rb
index 238daa4..5f12161 100644 (file)
@@ -7,6 +7,33 @@ module Mint
 
     subject { Builder }
 
+    describe 'build expression' do
+
+      before(:all) do
+        @original = '(x^-2 + 4)(y^3 --2)'
+        @normalized = '(x^-2 + 4) * (y^3 - (-2))'
+        @latex = '(x^-2 + 4)(y^3 - (-2))'
+      end
+
+      subject { Builder.build(@original) }
+
+      it 'original' do
+        subject.to_original.should == @original
+      end
+
+      it 'normalized' do
+        subject.normalize.should == @normalized
+      end
+
+      it 'to_s as normalized' do
+        subject.to_s.should == @normalized
+      end
+
+      it 'latex' do
+        subject.to_latex.should == @latex
+      end
+    end
+
     describe 'validates expression' do
 
       context 'valid expression' do
@@ -32,6 +59,7 @@ module Mint
           '(2 * ( 3 + 5 ) )',
           '     ( 2   * 3   +5)',
           '2 * (3) + 5',
+          '(x^3 + 2)(x^2- 3)(x + 5)',
         ].each do |expr|
           it "with parenthesis #{expr}" do
             expect { subject.build(expr) }.to_not raise_error
@@ -71,5 +99,18 @@ module Mint
         end
       end
     end
+
+    context 'null expression' do
+      [
+        ['empty string', ''],
+        ['nil', nil],
+      ].each do |name, value|
+        context name do
+          subject { Builder.build(value) }
+          it { subject.should be_an_instance_of(NullExpression) }
+        end
+      end
+    end
   end
 end
+