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 '1 / ((x + 4) * (x - 2) div 5)',
45 '\frac{1}{(x + 4)(x - 2) \div 5}',
46 '\frac{1}{(x + 4)(x - 2) \divide 5}',
59 '(-83.68) \times 10.23',
60 '(-83.68) \times 10.23',
72 '3.4 / 54 div (2 / 6)',
73 '\frac{3.4}{54} \div \frac{2}{6}',
74 '\frac{3.4}{54} \divide \frac{2}{6}',
108 '2\sqrt{2} \times 35',
109 '2\sqrt{2} \times 35',
111 [ '2i', '2 * %i', '2 * %i', '2\i', '2\i', ],
112 [ '2e', '2 * %e', '2 * %e', '2\e', '2\e', ],
113 [ '2pi', '2 * %pi', '2 * %pi', '2\pi', '2\pi', ],
114 ].each do |original, maxima, normalize, latex, ascii_math_ml|
122 @normalize = normalize
123 @ascii_math_ml = ascii_math_ml
126 subject { MintExpressionParser.new.parse(@original) }
129 subject.to_original.should == @original
133 subject.to_maxima.should == @maxima
137 subject.to_latex.should == @latex
140 it 'ascii_math_ml' do
141 subject.to_ascii_math_ml.should == @ascii_math_ml
145 subject.normalize.should == @normalize
148 it 'to_s as normalize' do
149 subject.to_s.should == @normalize
156 describe NullExpression do
158 subject { NullExpression.new }
160 before { @other = Expression.new('5', LiteralNode.new(5)) }
169 it { subject.__send__(meth).should be_empty }
172 it { subject.==(@other).should be_false }
173 it { subject.inspect.should match(/#<Mint::Expression:\d+ ''>/) }