1 # -*- coding: utf-8 -*-
3 require File.dirname(__FILE__) + '/spec_helper.rb'
9 describe 'comparing' do
11 ProblemExamples.get(:original, :existing).each do |expression, other|
13 expr = Mint::Builder.build(expression)
14 othr = Mint::Builder.build(other)
18 expr = Mint::Builder.build(expression)
19 othr = Mint::Builder.build(other)
20 othr_maxima = othr.to_maxima
21 othr.stub(:normalize => '')
22 othr.stub(:to_maxima => othr_maxima)
26 context 'null expression' do
27 ProblemExamples.get(:original, :existing).each do |expression, _|
29 subject { Mint::Builder.build(expression) }
30 before { @null = Mint::Builder.build(nil) }
31 it { subject.should_not == @null }
38 describe 'formating' do
42 '1 / (x + 4)(x - 2) div 5',
43 '1 / ((x + 4) * (x - 2) / 5)',
44 '\frac{1}{(x + 4) \times (x - 2) \div 5}',
45 '1 / ((x + 4) * (x - 2) div 5)',
46 '\frac{1}{(x + 4) \times (x - 2) \divide 5}',
58 '(-83.68) \times 10.23',
60 '(-83.68) \times 10.23',
72 '\frac{3.4}{54} \div \frac{2}{6}',
73 '3.4 / 54 div (2 / 6)',
74 '\frac{3.4}{54} \divide \frac{2}{6}',
93 '2\sqrt{2} \times 35',
95 '2\sqrt{2} \times 35',
97 [ '2i', '2 * %i', '2\i', '2 * %i', '2\i', ],
98 [ '2e', '2 * %e', '2\e', '2 * %e', '2\e', ],
99 [ '2pi', '2 * %pi', '2\pi', '2 * %pi', '2\pi', ],
100 ].each do |original, maxima, latex, normalize, ascii_math_ml|
108 @normalize = normalize
109 @ascii_math_ml = ascii_math_ml
112 subject { MintExpressionParser.new.parse(@original) }
115 subject.to_original.should == @original
119 subject.to_maxima.should == @maxima
123 subject.to_latex.should == @latex
127 subject.normalize.should == @normalize
130 it 'ascii_math_ml' do
131 subject.to_ascii_math_ml.should == @ascii_math_ml
134 it 'to_s as normalize' do
135 subject.to_s.should == @normalize
142 describe NullExpression do
144 subject { NullExpression.new }
146 before { @other = Expression.new('5', LiteralNode.new(5)) }
155 it { subject.__send__(meth).should be_empty }
158 it { subject.==(@other).should be_false }
159 it { subject.inspect.should match(/#<Mint::Expression:\d+ ''>/) }