spec/lib/function_spec.rb in dydx-0.1.4 vs spec/lib/function_spec.rb in dydx-0.1.25
- old
+ new
@@ -1,65 +1,39 @@
require 'spec_helper'
-describe Dydx::Function do
- before { reset }
+describe Dydx:Function do
+ # TODO: refactor
+ it{ expect(f(x, y)).to eq(f(x, y)) }
+ it{ expect(f(x, y)).to eq($f) }
+ it{ expect(f(x, y).algebra).to be_nil }
+ it{ expect(f(x, y).vars).to eq([:x, :y]) }
+ it{ expect{f(x, y, z)}.to raise_error(ArgumentError) }
+ it{ expect{f(x)}.to raise_error(ArgumentError) }
+ it{ expect(f(x, y) <= x * y ).to eq(f(x, y)) }
+ it{ expect(f(x, y)).to eq(f(x, y)) }
+ it{ expect(f(x, y)).to eq($f) }
+ it{ expect(f(x, y).algebra).to eq(x * y) }
+ it{ expect(f(x, y)).to eq(x * y) }
+ it{ expect(eval(f(x, y).to_s)).to eq(f(x, y)) }
+ it{ expect(f(x, y)).to eq(eval(f(x, y).to_s)) }
+ it{ expect(f(a, b)).to eq(a * b) }
+ it{ expect(f(2, 3)).to eq(6) }
+ it{ expect(f(a + b, c)).to eq((a + b) * c) }
+ it{ expect(d/dx(f(x, y))).to eq(y) }
+ it{ expect(d/dy(f(x, y))).to eq(x) }
+ it{ expect(d/dz(f(x, y))).to eq(0) }
- it 'ex1' do
- expect(f(x, y)).to eq(f(x, y))
- expect(f(x, y)).to eq($f)
- expect(f(x, y).algebra).to be_nil
- expect(f(x, y).vars).to eq([:x, :y])
- expect { f(x, y, z) }.to raise_error(ArgumentError)
- expect { f(x) }.to raise_error(ArgumentError)
- end
+ it{ expect(g(a, b) <= f(a + b, b)).to eq(g(a, b)) }
+ it{ expect(g(a, b)).to eq($g) }
+ it{ expect(g(2, 3)).to eq(15) }
- it 'ex2' do
- expect(f(x, y) <= x * y ).to eq(f(x, y))
- expect(f(x, y)).to eq(f(x, y))
- expect(f(x, y)).to eq($f)
- expect(f(x, y).algebra).to eq(x * y)
- expect(f(x, y)).to eq(x * y)
- expect(f(x, y)).to eq(eval(f(x, y).to_s))
- expect(f(a, b)).to eq(a * b)
- expect(f(2, x)).to eq(2 * x)
- expect(f(2, 3)).to eq(6)
- expect(f(a + b, c)).to eq((a + b) * c)
- expect(d/dx(f(x, y))).to eq(y)
- expect(d/dy(f(x, y))).to eq(x)
- expect(d/dz(f(x, y))).to eq(0)
- end
+ it{ expect(h(a, b, c) <= d/db(g(a, b))).to eq(h(a, b, c)) }
+ it{ expect(h(a, b, c) <= d/db(g(a, b))).to eq($h) }
+ it{ expect(h(a, b, c)).to eq(( ( 2 * b ) + a )) }
+ it{ expect(h(a, b, c).algebra).to eq(( ( 2 * b ) + a )) }
- it 'ex3' do
- f(x, y) <= x * y
- g(a, b) <= f(a + b, b)
- expect(g(a, b)).to eq((a + b) * b)
- expect(g(a, 3)).to eq(9 + 3 * a)
- expect(g(2, 3)).to eq(15)
- end
-
- it 'ex4' do
- f(a, b) <= (a + b) * b
- h(a, b, c) <= d/db(f(a, b))
- expect(h(a, b, c)).to eq(( a + ( 2 * b ) ))
- expect(h(a, b, c).algebra).to eq(( a + ( 2 * b ) ))
- end
-
- it 'ex5' do
+ it 'ex.4' do
+ $f = nil
f(x) <= log(x)
- expect(f(e)).to eq(1)
- expect(f(0)).to eq(-oo)
- expect(f(y)).to eq(log(y))
-
- g(x) <= d/dx(f(x))
- expect(g(1)).to eq(1)
- end
-
- it 'ex6' do
- f(x) <= sin(x)
- expect(f(pi)).to eq(0)
- expect(f(pi / 2)).to eq(1)
- expect(f(y)).to eq(sin(y))
-
- g(x) <= d/dx(f(x))
- expect(g(pi)).to eq(-1)
+ expect(f(a)).to eq(log(a))
end
end