spec/lib/helper_spec.rb in dydx-0.1.4 vs spec/lib/helper_spec.rb in dydx-0.1.25
- old
+ new
@@ -1,65 +1,67 @@
require 'spec_helper'
describe Helper do
include Helper
context '#is_n?' do
- it { expect(0.zero?).to be true }
- it { expect(_(0).zero?).to be true }
- it { expect(inverse(0, :+).zero?).to be true }
- it { expect(1.one?).to be true }
- it { expect(_(1).one?).to be true }
- it { expect(inverse(1, :*).one?).to be true }
- it { expect(-1.minus1?).to be true }
- it { expect(_(-1).minus1?).to be true }
+ it{ expect(0.is_0?).to be_true }
+ it{ expect(_(0).is_0?).to be_true }
+ it{ expect(inverse(0, :+).is_0?).to be_true }
+ it{ expect(1.is_1?).to be_true }
+ it{ expect(_(1).is_1?).to be_true }
+ it{ expect(inverse(1, :*).is_1?).to be_true }
+ it{ expect(-1.is_minus1?).to be_true }
+ it{ expect(_(-1).is_minus1?).to be_true }
end
- context '#multiple_of?' do
- it { expect(0.multiple_of?(x)).to be(true) }
+ context '#is_multiple_of' do
+ it{ expect(0.is_multiple_of(:x).to_s).to eq('0') }
+ it{ expect(_(0).is_multiple_of(:y).to_s).to eq('0')}
- it { expect(4.multiple_of?(_(2))).to be(true) }
- it { expect(_(4).multiple_of?(2)).to be(true) }
- it { expect(_(4).multiple_of?(_(2))).to be(true) }
+ it{ expect(:x.is_multiple_of(:x).to_s).to eq('1') }
+ it{ expect(:x.is_multiple_of(:y)).to be_false }
- it { expect(x.multiple_of?(x)).to be(true) }
- it { expect(x.multiple_of?(y)).to be(false) }
-
- it { expect((x * y).multiple_of?(x)).to be(true) }
- it { expect((x * y).multiple_of?(x)).to be(true) }
- it { expect((x * y).multiple_of?(z)).to be(false) }
+ it{ expect((:x * :y).is_multiple_of(:x)).to eq(:y) }
+ it{ expect((:x * :y).is_multiple_of(:y)).to eq(:x) }
+ it{ expect((:x * :y).is_multiple_of(:z)).to be_false }
end
- context '#like_term?' do
- it { expect(x.like_term?(x)).to be true }
- it { expect((2 * x).like_term?((3 * x))).to be true }
- end
-
context '#combinable?' do
- it { expect(:x.combinable?(:x, :+)).to be true }
- it { expect(:x.combinable?(2 * :x, :+)).to be true }
- it { expect((2 * :x).combinable?(:x, :+)).to be true }
- it { expect((2 * :x).combinable?(2 * :x, :+)).to be true }
- it { expect(:x.combinable?(:y, :+)).to be false }
- it { expect(1.combinable?(2, :+)).to be true }
- it { expect(:x.combinable?(:x, :*)).to be true }
- it { expect(:x.combinable?(:y, :*)).to be false }
- it { expect(1.combinable?(2, :*)).to be true }
- it { expect(0.combinable?(:x, :**)).to be true }
- it { expect(1.combinable?(:y, :**)).to be true }
+ it{ expect(:x.combinable?(:x, :+)).to be_true }
+ it{ expect(:x.combinable?(2 * :x, :+)).to be_true }
+ it{ expect((2 * :x).combinable?(:x, :+)).to be_true }
+ it{ expect((2 * :x).combinable?(2 * :x, :+)).to be_true }
+ it{ expect(:x.combinable?(:y, :+)).to be_false }
+ it{ expect(1.combinable?(2, :+)).to be_true }
+ it{ expect(:x.combinable?(:x, :*)).to be_true }
+ it{ expect(:x.combinable?(:y, :*)).to be_false }
+ it{ expect(1.combinable?(2, :*)).to be_true }
+ it{ expect(0.combinable?(:x, :^)).to be_true }
+ it{ expect(1.combinable?(:y, :^)).to be_true }
end
context '#distributive?' do
- it { expect(distributive?(:+, :*)).to be true }
- it { expect(distributive?(:+, :/)).to be true }
- it { expect(distributive?(:-, :*)).to be true }
- it { expect(distributive?(:-, :/)).to be true }
- it { expect(distributive?(:*, :**)).to be true }
- it { expect(distributive?(:/, :**)).to be true }
- it { expect(distributive?(:*, :+)).to be false }
- it { expect(distributive?(:**, :*)).to be false }
+ it{ expect(distributive?(:+, :*)).to be_true }
+ it{ expect(distributive?(:+, :/)).to be_true }
+ it{ expect(distributive?(:-, :*)).to be_true }
+ it{ expect(distributive?(:-, :/)).to be_true }
+ it{ expect(distributive?(:*, :^)).to be_true }
+ it{ expect(distributive?(:/, :^)).to be_true }
+ it{ expect(distributive?(:*, :+)).to be_false }
+ it{ expect(distributive?(:^, :*)).to be_false }
end
- it { expect(inverse(x, :+).inverse?(:+, x)).to be true }
- it { expect(x.inverse?(:+, inverse(x, :+))).to be true }
- it { expect(inverse(x, :*).inverse?(:*, x)).to be true }
- it { expect(x.inverse?(:*, inverse(x, :*))).to be true }
+ let(:addition) { (:x + :y) }
+ let(:subtraction) { (:x - :y) }
+ let(:multiplication){ (:x * :y) }
+ let(:division) { (:x / :y) }
+ let(:exponentiation){ (:x ^ :y) }
+
+ it{ expect(addition.addition?).to be_true }
+ it{ expect(multiplication.multiplication?).to be_true }
+ it{ expect(exponentiation.exponentiation?).to be_true }
+
+ it{ expect(inverse(:x, :+).inverse?(:+, :x)).to be_true }
+ it{ expect(:x.inverse?(:+, inverse(:x, :+))).to be_true }
+ it{ expect(inverse(:x, :*).inverse?(:*, :x)).to be_true }
+ it{ expect(:x.inverse?(:*, inverse(:x, :*))).to be_true }
end