1 # -*- coding: utf-8 -*-
3 require File.dirname(__FILE__) + '/spec_helper.rb'
10 describe 'build expression' do
13 @original = '(x^-2 + 4)(y^3 --2)'
14 @normalized = '(x^-2 + 4) * (y^3 - -2)'
15 @latex = '(x^-2 + 4) \times (y^3 - -2)'
18 subject { Builder.build(@original) }
21 subject.to_original.should == @original
25 subject.normalize.should == @normalized
28 it 'to_s as normalized' do
29 subject.to_s.should == @normalized
33 subject.to_latex.should == @latex
37 describe 'validates expression' do
39 context 'valid expression' do
49 it "without parenthesis #{expr}" do
50 expect { subject.build(expr) }.to_not raise_error
56 '2 * (( 3 + 5 ) - 2)',
62 '(x^3 + 2)(x^2- 3)(x + 5)',
64 it "with parenthesis #{expr}" do
65 expect { subject.build(expr) }.to_not raise_error
70 context 'invalid expression' do
80 it "without parenthesis #{expr}" do
81 expect { subject.build(expr) }.to raise_error
96 it "with parenthesis #{expr}" do
97 expect { subject.build(expr) }.to raise_error