spec/lib/danica/function_spec.rb in danica-2.6.2 vs spec/lib/danica/function_spec.rb in danica-2.6.3
- old
+ new
@@ -32,10 +32,40 @@
described_class.build(*variables) do
Danica::Operator::Power.new(x, y)
end
end
+ describe '.for' do
+ let(:expression_class) { Danica::Expression::Gauss }
+ let(:expression) { expression_class.new }
+ subject do
+ described_class.for(expression_class).new
+ end
+
+ it 'returns a function' do
+ expect(subject).to be_a(described_class)
+ end
+
+ it 'behaves like a function' do
+ expect do
+ subject.to_tex
+ end.not_to raise_error
+ end
+
+ it 'creates a funcion out of an expression' do
+ expect(subject.to_tex).to eq("f(x, \\mu, \\sigma) = #{expression.to_tex}")
+ end
+
+ context 'when passing an operator' do
+ let(:expression_class) { Danica::Operator::Cos }
+
+ it do
+ expect(subject.to_tex).to eq("f(value) = #{expression.to_tex}")
+ end
+ end
+ end
+
describe '.build' do
let(:function) do
function_class.new(name: :f)
end
@@ -50,11 +80,11 @@
expect(function_class.superclass).to eq(described_class)
end
end
context 'when creating a class using build' do
- let(:function_class) { Danica::Function::Hyperbole }
+ let(:function_class) { Danica::Function::Parabole }
it 'has the defined variables on class definition' do
expect(function_class.variables_names).to eq([:x])
end
@@ -74,10 +104,10 @@
end
end
end
context 'when using a class that inherits from another class' do
- let(:function_class) { Danica::Function::SaddleHyperbole }
+ let(:function_class) { Danica::Function::SaddleParabole }
it 'has the defined variables on class definition' do
expect(function_class.variables_names).to eq([:x, :y])
end