dydx 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,6 +37,10 @@ module Dydx
37
37
  "( #{f.to_s} #{@operator} #{g.to_s} )"
38
38
  end
39
39
  end
40
+
41
+ def include?(x)
42
+ f == x || g == x
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -13,13 +13,13 @@ module Dydx
13
13
  else
14
14
  super(x)
15
15
  end
16
- elsif ([self.operator, operator].sort == [:+, :-]) && ( f == x || g == x )
16
+ elsif ([self.operator, operator].sort == [:+, :-]) && include?(x)
17
17
  if f == x
18
18
  g
19
19
  elsif g == x
20
20
  f
21
21
  end
22
- elsif (self.operator == operator) && ( f == x || g == x )
22
+ elsif (self.operator == operator) && include?(x)
23
23
  if f == x
24
24
  f.send(operator, x).send(operator, g)
25
25
  elsif g == x
@@ -41,13 +41,13 @@ module Dydx
41
41
  else
42
42
  super(x)
43
43
  end
44
- elsif ([self.operator, operator].sort == [:*, :/]) && ( f == x || g == x )
44
+ elsif ([self.operator, operator].sort == [:*, :/]) && include?(x)
45
45
  if f == x
46
46
  g
47
47
  elsif g == x
48
48
  f
49
49
  end
50
- elsif (self.operator == operator) && ( f == x || g == x )
50
+ elsif (self.operator == operator) && include?(x)
51
51
  if f == x
52
52
  f.send(operator, x).send(operator, g)
53
53
  elsif g == x
@@ -1,3 +1,3 @@
1
1
  module Dydx
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -4,4 +4,28 @@ describe Dydx do
4
4
  it 'has a version number' do
5
5
  expect(Dydx::VERSION).not_to be nil
6
6
  end
7
+
8
+ context 'ex1' do
9
+ $a = (:x ^ :n)
10
+ let(:d1){ da/dx }
11
+ let(:d2){ d/dx($a) }
12
+ it{ expect(d1.to_s).to eq('( n * ( x ^ ( n - 1 ) ) )') }
13
+ it{ expect(d2.to_s).to eq('( n * ( x ^ ( n - 1 ) ) )') }
14
+ end
15
+
16
+ context 'ex2' do
17
+ $b = (:x ^ (:x * 2))
18
+ let(:d1){ db/dx }
19
+ let(:d2){ d/dx($b) }
20
+ it{ expect(d1.to_s).to eq('( ( x * 2 ) * ( x ^ ( ( x * 2 ) - 1 ) ) )') }
21
+ it{ expect(d2.to_s).to eq('( ( x * 2 ) * ( x ^ ( ( x * 2 ) - 1 ) ) )') }
22
+ end
23
+
24
+ context 'ex3' do
25
+ $c = (:t ^ 2) / 2
26
+ let(:d1){ dc/dt }
27
+ let(:d2){ d/dt($c) }
28
+ it{ expect(d1.to_s).to eq('t') }
29
+ it{ expect(d2.to_s).to eq('t') }
30
+ end
7
31
  end
@@ -50,25 +50,8 @@ describe Dydx::Algebra::Formula do
50
50
  it{ expect(exponentiation.d(:z).to_s).to eq('0') }
51
51
  end
52
52
 
53
- context 'With Symbol' do
54
- $a = (:x ^ :n)
55
- let(:d1){ da/dx }
56
- let(:d2){ d/dx($a) }
57
- it{ expect(d1.to_s).to eq('( n * ( x ^ ( n - 1 ) ) )') }
58
- it{ expect(d2.to_s).to eq('( n * ( x ^ ( n - 1 ) ) )') }
53
+ describe '#include?' do
54
+ it{ expect(addition.include?(:x)).to be_true }
55
+ it{ expect(addition.include?(:z)).to be_false }
59
56
  end
60
-
61
- context 'With Symbol' do
62
- $b = (:x ^ (:x * 2))
63
- let(:d1){ db/dx }
64
- let(:d2){ d/dx($b) }
65
- it{ expect(d1.to_s).to eq('( ( x * 2 ) * ( x ^ ( ( x * 2 ) - 1 ) ) )') }
66
- it{ expect(d2.to_s).to eq('( ( x * 2 ) * ( x ^ ( ( x * 2 ) - 1 ) ) )') }
67
- end
68
-
69
- $c = (:t ^ 2) / 2
70
- let(:d1){ dc/dt }
71
- let(:d2){ d/dt($c) }
72
- it{ expect(d1.to_s).to eq('t') }
73
- it{ expect(d2.to_s).to eq('t') }
74
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dydx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-11 00:00:00.000000000 Z
12
+ date: 2014-05-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -132,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  segments:
134
134
  - 0
135
- hash: 3588905385522331028
135
+ hash: -708242121294730939
136
136
  required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  none: false
138
138
  requirements:
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  version: '0'
142
142
  segments:
143
143
  - 0
144
- hash: 3588905385522331028
144
+ hash: -708242121294730939
145
145
  requirements: []
146
146
  rubyforge_project:
147
147
  rubygems_version: 1.8.23