dydx 0.1.314 → 0.1.412

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +25 -0
  3. data/.travis.yml +3 -1
  4. data/Gemfile +1 -0
  5. data/README.md +4 -2
  6. data/Rakefile +5 -8
  7. data/dydx.gemspec +13 -13
  8. data/lib/dydx.rb +20 -27
  9. data/lib/dydx/algebra.rb +8 -6
  10. data/lib/dydx/algebra/formula.rb +53 -28
  11. data/lib/dydx/algebra/inverse.rb +2 -2
  12. data/lib/dydx/algebra/operator/formula.rb +0 -1
  13. data/lib/dydx/algebra/operator/general.rb +0 -1
  14. data/lib/dydx/algebra/operator/inverse.rb +0 -1
  15. data/lib/dydx/algebra/operator/num.rb +0 -1
  16. data/lib/dydx/algebra/operator/parts/base.rb +2 -2
  17. data/lib/dydx/algebra/operator/parts/formula.rb +61 -40
  18. data/lib/dydx/algebra/operator/parts/general.rb +83 -32
  19. data/lib/dydx/algebra/operator/parts/inverse.rb +4 -4
  20. data/lib/dydx/algebra/operator/parts/num.rb +16 -11
  21. data/lib/dydx/algebra/operator/parts/symbol.rb +2 -2
  22. data/lib/dydx/algebra/set.rb +82 -122
  23. data/lib/dydx/delta.rb +1 -1
  24. data/lib/dydx/function.rb +1 -1
  25. data/lib/dydx/helper.rb +43 -66
  26. data/lib/dydx/integrand.rb +7 -6
  27. data/lib/dydx/version.rb +1 -1
  28. data/spec/dydx_spec.rb +3 -3
  29. data/spec/lib/algebra/formula_spec.rb +41 -41
  30. data/spec/lib/algebra/operator/parts/base_spec.rb +5 -5
  31. data/spec/lib/algebra/operator/parts/formula_spec.rb +57 -57
  32. data/spec/lib/algebra/operator/parts/inverse_spec.rb +8 -8
  33. data/spec/lib/algebra/set_spec.rb +193 -150
  34. data/spec/lib/delta_spec.rb +23 -25
  35. data/spec/lib/function_spec.rb +4 -6
  36. data/spec/lib/helper_spec.rb +44 -51
  37. data/spec/lib/integrand_spec.rb +12 -10
  38. data/spec/spec_helper.rb +2 -1
  39. metadata +6 -7
  40. data/lib/dydx/algebra/operator/parts.rb +0 -6
  41. data/lib/dydx/algebra/operator/parts/interface.rb +0 -22
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Dydx::Algebra::Operator::Parts::Inverse do
4
- it{ expect(inverse(:x, :+).to_s).to eq('( - x )') }
5
- it{ expect(inverse(:x, :*).to_s).to eq('( 1 / x )') }
4
+ it { expect(inverse(x, :+).to_s).to eq('( - x )') }
5
+ it { expect(inverse(x, :*).to_s).to eq('( 1 / x )') }
6
6
 
7
- it{ expect(inverse(:x, :+)).to eq(inverse(:x, :+)) }
8
- it{ expect(inverse(:x, :*)).to eq(inverse(:x, :*)) }
7
+ it { expect(inverse(x, :+)).to eq(inverse(x, :+)) }
8
+ it { expect(inverse(x, :*)).to eq(inverse(x, :*)) }
9
9
 
10
- it{ expect(:x - :x).to eq(e0) }
11
- it{ expect(:x / :x).to eq(e1) }
12
- it{ expect(inverse(:x, :+) + :x).to eq(e0) }
13
- it{ expect(inverse(:x, :*) * :x).to eq(e1) }
10
+ it { expect(x - x).to eq(0) }
11
+ it { expect(x / x).to eq(1) }
12
+ it { expect(inverse(x, :+) + x).to eq(0) }
13
+ it { expect(inverse(x, :*) * x).to eq(1) }
14
14
  end
@@ -1,75 +1,82 @@
1
1
  require 'spec_helper'
2
2
  # HOTFIX: Refactor by using context or describe
3
3
  describe Dydx::Algebra::Set do
4
- it{ expect(_(1)).to eq(_(1)) }
5
- it{ expect(_(-1)).to eq(_(-1)) }
6
- it{ expect(e0).to eq(e0) }
7
- it{ expect(e1).to eq(e1) }
4
+ it { expect(_(1)).to eq(_(1)) }
5
+ it { expect(_(-1)).to eq(_(-1)) }
6
+ it { expect(e0).to eq(e0) }
7
+ it { expect(e1).to eq(e1) }
8
8
 
9
- it{ expect(e).to eq(e) }
10
- it{ expect(pi).to eq(pi) }
9
+ it { expect(e).to eq(e) }
10
+ it { expect(pi).to eq(pi) }
11
11
 
12
12
  it { expect(log10(1)).to eq(e0) }
13
13
  it { expect(log10(10)).to eq(e1) }
14
- it { expect(log10(10 ^ n)).to eq(n) }
15
- it { expect(log10(3 ^ n)).to eq(n * log10( 3 )) }
14
+ it { expect(log10(10 ** n)).to eq(n) }
15
+ it { expect(log10(3 ** n)).to eq(n * log10( 3 )) }
16
16
 
17
17
  it { expect(log2(1)).to eq(e0) }
18
18
  it { expect(log2(2)).to eq(e1) }
19
- it { expect(log2(2 ^ n)).to eq(n) }
20
- it { expect(log2(3 ^ n)).to eq(n * log2( 3 )) }
21
-
22
- it{ expect(log(1)).to eq(0) }
23
- it{ expect(log(e)).to eq(1) }
24
- it{ expect(log(e ^ n)).to eq(n) }
25
-
26
- it{ expect(sin(pi)).to eq(0) }
27
-
28
- it{ expect(cos(0)).to eq(1) }
29
- it{ expect(cos(pi)).to eq(-1) }
30
- it{ expect(cos(2 * pi)).to eq(1) }
19
+ it { expect(log2(2 ** n)).to eq(n) }
20
+ it { expect(log2(3 ** n)).to eq(n * log2( 3 )) }
21
+
22
+ it { expect(log(1)).to eq(0) }
23
+ it { expect(log(e)).to eq(1) }
24
+ it { expect(log(e ** n)).to eq(n) }
25
+
26
+ it { expect(sin(0)).to eq(0) }
27
+ it { expect(sin(pi / 2)).to eq(1) }
28
+ it { expect(sin(pi)).to eq(0) }
29
+ it { expect(sin(3 * pi / 2)).to eq(-1) }
30
+ it { expect(sin(2 * pi)).to eq(0) }
31
+ it { expect(sin(3 * pi)).to eq(0) }
32
+
33
+ it { expect(cos(0)).to eq(1) }
34
+ it { expect(cos(pi / 2)).to eq(0) }
35
+ it { expect(cos(pi)).to eq(-1) }
36
+ it { expect(cos(3 * pi / 2)).to eq(0) }
37
+ it { expect(cos(2 * pi)).to eq(1) }
31
38
 
32
39
  describe '#to_s' do
33
- it{ expect(e.to_s).to eq('e') }
40
+ it { expect(e.to_s).to eq('e') }
34
41
 
35
- it{ expect(1.to_s).to eq('1') }
42
+ it { expect(1.to_s).to eq('1') }
36
43
 
37
- it{ expect(1.0.to_s).to eq('1.0') }
44
+ it { expect(1.0.to_s).to eq('1.0') }
38
45
 
39
- it{ expect(e1.to_s).to eq('1') }
46
+ it { expect(e1.to_s).to eq('1') }
40
47
 
41
- it{ expect(pi.to_s).to eq('pi') }
48
+ it { expect(pi.to_s).to eq('pi') }
42
49
 
43
- it{ expect(cos(x).to_s).to eq('cos( x )') }
44
- it{ expect(sin(x).to_s).to eq('sin( x )') }
45
- it{ expect(tan(x).to_s).to eq('tan( x )') }
50
+ it { expect(cos(x).to_s).to eq('cos( x )') }
51
+ it { expect(sin(x).to_s).to eq('sin( x )') }
52
+ it { expect(tan(x).to_s).to eq('tan( x )') }
46
53
 
47
- it{ expect(x.to_s).to eq('x') }
54
+ it { expect(x.to_s).to eq('x') }
48
55
  end
49
56
 
50
57
  describe '#==' do
51
- it{ expect(_(1) == _(1)).to be_true }
58
+ it { expect(_(1) == _(1)).to be true }
52
59
  end
53
60
 
54
61
  describe '#subst' do
55
- it{ expect(1.subst).to eq(1) }
56
- it{ expect(1.0.subst).to eq(1.0) }
57
- it{ expect(e.subst).to eq(e) }
58
- it{ expect(pi.subst).to eq(pi) }
59
- it{ expect(sin(x).subst(x: 3)).to eq(sin(3)) }
60
- it{ expect(cos(x).subst(x: pi)).to eq(-1) }
61
- it{ expect(tan(0).subst(x: pi)).to eq(0) }
62
- it{ expect(log(x).subst(x: e)).to eq(1) }
63
- it{ expect(log10(x).subst(x: 7)).to eq(log10(7)) }
64
- it{ expect(log2(2).subst(x: 2)).to eq(1) }
65
- it{ expect(x.subst(x: 2)).to eq(2) }
66
- it{ expect(x.subst(y: 2)).to eq(x) }
62
+ it { expect(1.subst).to eq(1) }
63
+ it { expect(1.0.subst).to eq(1.0) }
64
+ it { expect(e.subst).to eq(e) }
65
+ it { expect(pi.subst).to eq(pi) }
66
+ it { expect(sin(x).subst(x: 3)).to eq(sin(3)) }
67
+ it { expect(cos(x).subst(x: pi)).to eq(-1) }
68
+ it { expect(tan(0).subst(x: pi)).to eq(0) }
69
+ it { expect(log(x).subst(x: e)).to eq(1) }
70
+ it { expect(log10(x).subst(x: 7)).to eq(log10(7)) }
71
+ it { expect(log2(2).subst(x: 2)).to eq(1) }
72
+ it { expect(x.subst(x: 2)).to eq(2) }
73
+ it { expect(x.subst(y: 2)).to eq(x) }
67
74
  end
68
75
 
69
76
  describe '#differentiate' do
70
77
  it { expect(e.d).to eq(0) }
71
- it { expect((e ^ x).d).to eq(e ^ x) }
72
- it { expect((e ^ (x + y)).d).to eq(e ^ ( x + y )) }
78
+ it { expect((e ** x).d).to eq(e ** x) }
79
+ it { expect((e ** (x + y)).d).to eq(e ** ( x + y )) }
73
80
 
74
81
  it { expect(pi.d(x)).to eq(0) }
75
82
 
@@ -79,149 +86,185 @@ describe Dydx::Algebra::Set do
79
86
 
80
87
  it { expect(sin(x).d).to eq(cos(x)) }
81
88
  it { expect(cos(x).d).to eq(- sin(x)) }
82
- it { expect(tan(x).d).to eq(1 / cos(x) ^ 2) }
89
+ it { expect(tan(x).d).to eq(1 / cos(x) ** 2) }
83
90
 
84
91
  it { expect(log(x).d).to eq(1 / x) }
85
92
  it { expect(log10(x).d).to eq(1 / ( x * log( 10 ) )) }
86
93
  it { expect(log2(x).d).to eq(1 / ( x * log( 2 ) )) }
87
94
 
88
- it{ expect(x.d(x)).to eq(1) }
95
+ it { expect(x.d(x)).to eq(1) }
89
96
  end
90
97
 
91
98
  describe 'Calculate' do
92
99
  context 'E with Fixnum' do
93
- it{ expect(e + 0).to eq(e) }
94
- it{ expect(e - 0).to eq(e) }
95
- it{ expect((e * 0).to_s).to eq('0') }
96
- it{ expect(e * 1).to eq(e) }
97
- it{ expect{(e / 0).to_s}.to raise_error(ZeroDivisionError) }
98
- it{ expect(e / 1).to eq(e) }
99
- it{ expect((e ^ 0).to_s).to eq('1') }
100
+ it { expect(e + 0).to eq(e) }
101
+ it { expect(e - 0).to eq(e) }
102
+ it { expect((e * 0).to_s).to eq('0') }
103
+ it { expect(e * 1).to eq(e) }
104
+ it { expect { (e / 0).to_s }.to raise_error(ZeroDivisionError) }
105
+ it { expect(e / 1).to eq(e) }
106
+ it { expect((e ** 0).to_s).to eq('1') }
100
107
  end
101
108
 
102
109
  context 'Fixnum with Formula' do
103
- let(:formula) { (:x + :y) }
104
- it{ expect((0 + formula).to_s).to eq(formula.to_s) }
105
- it{ expect((0 - formula).to_s).to eq('( - ( x + y ) )') }
106
- it{ expect((0 * formula).to_s).to eq('0') }
107
- it{ expect((1 * formula).to_s).to eq(formula.to_s) }
108
- it{ expect((0 / formula).to_s).to eq('0') }
109
- it{ expect((1 / formula).to_s).to eq('( 1 / ( x + y ) )') }
110
- it{ expect((0 ^ formula).to_s).to eq('0') }
111
- it{ expect((1 ^ formula).to_s).to eq('1') }
110
+ let(:formula) { (x + y) }
111
+ it { expect(0 + formula).to eq(formula) }
112
+ it { expect(0 - formula).to eq( - ( x + y ) ) }
113
+ it { expect(0 * formula).to eq(0) }
114
+ it { expect(1 * formula).to eq(formula) }
115
+ it { expect(0 / formula).to eq(0) }
116
+ it { expect(1 / formula).to eq( 1 / ( x + y ) ) }
117
+ it { expect(0 ** formula).to eq(0) }
118
+ it { expect(1 ** formula).to eq(1) }
112
119
  end
113
120
 
114
121
  context 'Fixnum with Symbol' do
115
- it{ expect(0 + :x).to eq(:x) }
116
- it{ expect((0 - :x).to_s).to eq('( - x )') }
117
- it{ expect((0 * :x).to_s).to eq('0') }
118
- it{ expect(1 * :x).to eq(:x) }
119
- it{ expect((0 / :x).to_s).to eq('0') }
120
- it{ expect((1 / :x).to_s).to eq('( 1 / x )') }
121
- it{ expect((0 ^ :x).to_s).to eq('0') }
122
- it{ expect((1 ^ :x).to_s).to eq('1') }
122
+ it { expect(0 + x).to eq(x) }
123
+ it { expect(0 - x).to eq(- x) }
124
+ it { expect(0 * x).to eq(0) }
125
+ it { expect(1 * x).to eq(x) }
126
+ it { expect(0 / x).to eq(0) }
127
+ it { expect(1 / x).to eq( 1 / x ) }
128
+ it { expect(0 ** x).to eq(0) }
129
+ it { expect(1 ** x).to eq(1) }
123
130
  end
124
131
 
125
132
  context 'Fixnum with Fixnum' do
126
- it{ expect(0 + 3).to eq(3) }
127
- it{ expect(3 + 0).to eq(3) }
128
- it{ expect(2 + 3).to eq(5) }
129
-
130
- it{ expect(0 - 3).to eq(-3) }
131
- it{ expect(3 - 0).to eq(3) }
132
- it{ expect(2 - 3).to eq(-1) }
133
-
134
- it{ expect(0 * 3).to eq(0) }
135
- it{ expect(3 * 0).to eq(0) }
136
- it{ expect(1 * 3).to eq(3) }
137
- it{ expect(3 * 1).to eq(3) }
138
- it{ expect(3 * 2).to eq(6) }
139
-
140
- it{ expect((0 / 3).to_s).to eq('0') }
141
- it{ expect{(3 / 0).to_s}.to raise_error(ZeroDivisionError) }
142
- it{ expect((3 / 1).to_s).to eq('3') }
133
+ it { expect(0 + 3).to eq(3) }
134
+ it { expect(3 + 0).to eq(3) }
135
+ it { expect(2 + 3).to eq(5) }
136
+
137
+ it { expect(0 - 3).to eq(-3) }
138
+ it { expect(3 - 0).to eq(3) }
139
+ it { expect(2 - 3).to eq(-1) }
140
+
141
+ it { expect(0 * 3).to eq(0) }
142
+ it { expect(3 * 0).to eq(0) }
143
+ it { expect(1 * 3).to eq(3) }
144
+ it { expect(3 * 1).to eq(3) }
145
+ it { expect(3 * 2).to eq(6) }
146
+
147
+ it { expect((0 / 3).to_s).to eq('0') }
148
+ it { expect { (3 / 0).to_s }.to raise_error(ZeroDivisionError) }
149
+ it { expect((3 / 1).to_s).to eq('3') }
143
150
  # TODO:
144
- it{ expect((2 / 3).to_s).to eq('0') }
145
-
151
+ it { expect((2 / 3).to_s).to eq('0') }
146
152
 
147
- it{ expect((0 ^ 3).to_s).to eq('0') }
148
- it{ expect((3 ^ 0).to_s).to eq('1') }
149
- it{ expect((1 ^ 3).to_s).to eq('1') }
150
- it{ expect((3 ^ 1).to_s).to eq('3') }
151
- it{ expect((3 ^ 2).to_s).to eq('9') }
153
+ it { expect((0 ** 3).to_s).to eq('0') }
154
+ it { expect((3 ** 0).to_s).to eq('1') }
155
+ it { expect((1 ** 3).to_s).to eq('1') }
156
+ it { expect((3 ** 1).to_s).to eq('3') }
157
+ it { expect((3 ** 2).to_s).to eq('9') }
152
158
  end
153
159
 
154
160
  context 'Float with Formula' do
155
161
  let(:formula) { (:x + :y) }
156
- it{ expect((0.0 + formula).to_s).to eq(formula.to_s) }
157
- it{ expect((0.0 - formula).to_s).to eq('( - ( x + y ) )') }
158
- it{ expect((0.0 * formula).to_s).to eq('0') }
159
- it{ expect((1.0 * formula).to_s).to eq(formula.to_s) }
160
- it{ expect((0.0 / formula).to_s).to eq('0') }
161
- it{ expect((1.0 / formula).to_s).to eq('( 1 / ( x + y ) )') }
162
- it{ expect((0.0 ^ formula).to_s).to eq('0') }
163
- it{ expect((1.0 ^ formula).to_s).to eq('1') }
162
+ it { expect((0.0 + formula).to_s).to eq(formula.to_s) }
163
+ it { expect((0.0 - formula).to_s).to eq('( - ( x + y ) )') }
164
+ it { expect((0.0 * formula).to_s).to eq('0') }
165
+ it { expect((1.0 * formula).to_s).to eq(formula.to_s) }
166
+ it { expect((0.0 / formula).to_s).to eq('0') }
167
+ it { expect((1.0 / formula).to_s).to eq('( 1 / ( x + y ) )') }
168
+ it { expect((0.0 ** formula).to_s).to eq('0') }
169
+ it { expect((1.0 ** formula).to_s).to eq('1') }
164
170
  end
165
171
 
166
172
  context 'Float with Symbol' do
167
- it{ expect(0.0 + :x).to eq(:x) }
168
- it{ expect((0.0 - :x).to_s).to eq('( - x )') }
169
- it{ expect((0.0 * :x).to_s).to eq('0') }
170
- it{ expect(1.0 * :x).to eq(:x) }
171
- it{ expect((0.0 / :x).to_s).to eq('0') }
172
- it{ expect((1.0 / :x).to_s).to eq('( 1 / x )') }
173
- it{ expect((0.0 ^ :x).to_s).to eq('0') }
174
- it{ expect((1.0 ^ :x).to_s).to eq('1') }
173
+ it { expect(0.0 + :x).to eq(:x) }
174
+ it { expect((0.0 - :x).to_s).to eq('( - x )') }
175
+ it { expect((0.0 * :x).to_s).to eq('0') }
176
+ it { expect(1.0 * :x).to eq(:x) }
177
+ it { expect((0.0 / :x).to_s).to eq('0') }
178
+ it { expect((1.0 / :x).to_s).to eq('( 1 / x )') }
179
+ it { expect((0.0 ** :x).to_s).to eq('0') }
180
+ it { expect((1.0 ** :x).to_s).to eq('1') }
175
181
  end
176
182
 
177
183
  context 'Float with Float' do
178
- it{ expect(0.0 + 3.0).to eq(3.0) }
179
- it{ expect(3.0 + 0.0).to eq(3.0) }
180
- it{ expect(2.0 + 3.0).to eq(5.0) }
181
-
182
- it{ expect(0.0 - 3.0).to eq(-3.0) }
183
- it{ expect(3.0 - 0.0).to eq(3.0) }
184
- it{ expect(2.0 - 3.0).to eq(-1.0) }
185
-
186
- it{ expect(0.0 * 3.0).to eq(0.0) }
187
- it{ expect(3.0 * 0.0).to eq(0.0) }
188
- it{ expect(1.0 * 3.0).to eq(3.0) }
189
- it{ expect(3.0 * 1.0).to eq(3.0) }
190
- it{ expect(3.0 * 2.0).to eq(6.0) }
191
-
192
- it{ expect(0.0 / 3.0).to eq(0.0) }
193
- it{ expect(3.0 / 0.0).to eq(oo) }
194
- it{ expect(3.0 / 1.0).to eq(3.0) }
184
+ it { expect(0.0 + 3.0).to eq(3.0) }
185
+ it { expect(3.0 + 0.0).to eq(3.0) }
186
+ it { expect(2.0 + 3.0).to eq(5.0) }
187
+
188
+ it { expect(0.0 - 3.0).to eq(-3.0) }
189
+ it { expect(3.0 - 0.0).to eq(3.0) }
190
+ it { expect(2.0 - 3.0).to eq(-1.0) }
191
+
192
+ it { expect(0.0 * 3.0).to eq(0.0) }
193
+ it { expect(3.0 * 0.0).to eq(0.0) }
194
+ it { expect(1.0 * 3.0).to eq(3.0) }
195
+ it { expect(3.0 * 1.0).to eq(3.0) }
196
+ it { expect(3.0 * 2.0).to eq(6.0) }
197
+
198
+ it { expect(0.0 / 3.0).to eq(0.0) }
199
+ it { expect(3.0 / 0.0).to eq(oo) }
200
+ it { expect(3.0 / 1.0).to eq(3.0) }
195
201
  # TODO:
196
- it{ expect(2.0 / 3.0).to eq(0.6666666666666666) }
202
+ it { expect(2.0 / 3.0).to eq(0.6666666666666666) }
197
203
 
198
-
199
- it{ expect(0.0 ^ 3.0).to eq(0.0) }
200
- it{ expect(3.0 ^ 0.0).to eq(1.0) }
201
- it{ expect(1.0 ^ 3.0).to eq(1.0) }
202
- it{ expect(3.0 ^ 1.0).to eq(3.0) }
203
- it{ expect(3.0 ^ 2.0).to eq(9.0) }
204
+ it { expect(0.0 ** 3.0).to eq(0.0) }
205
+ it { expect(3.0 ** 0.0).to eq(1.0) }
206
+ it { expect(1.0 ** 3.0).to eq(1.0) }
207
+ it { expect(3.0 ** 1.0).to eq(3.0) }
208
+ it { expect(3.0 ** 2.0).to eq(9.0) }
204
209
  end
205
210
 
206
211
  context 'Pi with Fixnum' do
207
- it{ expect(pi + 0).to eq(pi) }
208
- it{ expect(pi - 0).to eq(pi) }
209
- it{ expect((pi * 0).to_s).to eq('0') }
210
- it{ expect(pi * 1).to eq(pi) }
211
- it{ expect{(pi / 0).to_s}.to raise_error(ZeroDivisionError) }
212
- it{ expect(pi / 1).to eq(pi) }
213
- it{ expect((pi ^ 0).to_s).to eq('1') }
212
+ it { expect(pi + 0).to eq(pi) }
213
+ it { expect(pi - 0).to eq(pi) }
214
+ it { expect((pi * 0).to_s).to eq('0') }
215
+ it { expect(pi * 1).to eq(pi) }
216
+ it { expect { (pi / 0).to_s }.to raise_error(ZeroDivisionError) }
217
+ it { expect(pi / 1).to eq(pi) }
218
+ it { expect((pi ** 0).to_s).to eq('1') }
214
219
  end
215
220
 
216
221
  context 'Symbol with Fixnum' do
217
- it{ expect(:x + 0).to eq(:x) }
218
- it{ expect(:x - 0).to eq(:x) }
219
- it{ expect((:x * 0).to_s).to eq('0') }
220
- it{ expect(:x * 1).to eq(:x) }
221
- it{ expect{(:x / 0).to_s}.to raise_error(ZeroDivisionError) }
222
- it{ expect(:x / 1).to eq(:x) }
223
- it{ expect((:x ^ 0).to_s).to eq('1') }
224
- it{ expect(:x ^ 1).to eq(:x) }
222
+ it { expect(x + 0).to eq(x) }
223
+ it { expect(x - 0).to eq(x) }
224
+ it { expect(x * 0).to eq(0) }
225
+ it { expect(x * 1).to eq(x) }
226
+ it { expect { x / 0 }.to raise_error(ZeroDivisionError) }
227
+ it { expect(x / 1).to eq(x) }
228
+ it { expect(x ** 0).to eq(1) }
229
+ it { expect(x ** 1).to eq(x) }
230
+ end
231
+
232
+ context 'Num with Num' do
233
+ it { expect(_(1) + _(2)).to eq(3) }
234
+ it { expect(_(1) - _(2)).to eq(-1) }
235
+ it { expect(_(1) * _(2)).to eq(2) }
236
+ it { expect((_(1) / _(2)).to_s).to eq('( 1 / 2 )') }
237
+ it { expect(_(1) % _(2)).to eq(1) }
238
+ end
239
+ end
240
+
241
+ describe Dydx::Algebra::Set::Num do
242
+ describe :< do
243
+ it { expect(_(1) < _(2)).to be(true) }
244
+ it { expect(_(1) < 2).to be(true) }
245
+ it { expect(_(2) < _(1)).to be(false) }
246
+ it { expect(_(2) < 1).to be(false) }
247
+ end
248
+
249
+ describe :<= do
250
+ it { expect(_(1) <= _(2)).to be(true) }
251
+ it { expect(_(1) <= 2).to be(true) }
252
+ it { expect(_(2) <= _(1)).to be(false) }
253
+ it { expect(_(2) <= 1).to be(false) }
254
+ end
255
+
256
+ describe :> do
257
+ it { expect(_(1) > _(2)).to be(false) }
258
+ it { expect(_(1) > 2).to be(false) }
259
+ it { expect(_(2) > _(1)).to be(true) }
260
+ it { expect(_(2) > 1).to be(true) }
261
+ end
262
+
263
+ describe :>= do
264
+ it { expect(_(1) >= _(2)).to be(false) }
265
+ it { expect(_(1) >= 2).to be(false) }
266
+ it { expect(_(2) >= _(1)).to be(true) }
267
+ it { expect(_(2) >= 1).to be(true) }
225
268
  end
226
269
  end
227
- end
270
+ end
@@ -1,37 +1,35 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Dydx:Delta do
4
- it{ expect(d.class).to eq(Delta) }
5
- it{ expect(dx.class).to eq(Delta) }
6
- it{ expect(dx.var).to eq(:x) }
7
- it{ expect(dx(y).class).to eq(Delta) }
8
- it{ expect(dx(y).var).to eq(:x) }
9
- it{ expect(dx(y).function).to eq(:y) }
10
- it{ expect{dxy}.to raise_error(NameError) }
3
+ describe Dydx::Delta do
4
+ it { expect(d.class).to eq(Delta) }
5
+ it { expect(dx.class).to eq(Delta) }
6
+ it { expect(dx.var).to eq(:x) }
7
+ it { expect(dx(y).class).to eq(Delta) }
8
+ it { expect(dx(y).var).to eq(:x) }
9
+ it { expect(dx(y).function).to eq(:y) }
10
+ it { expect { dxy }.to raise_error(NameError) }
11
11
 
12
- before(:each) do
13
- $y = example
14
- end
12
+ before { reset }
15
13
 
16
- context 'ex1' do
17
- let(:example) { x ^ n }
18
- it { expect(dy/dx).to eq( n * ( x ^ ( n - 1 ) ) ) }
19
- it { expect(d/dx($y)).to eq( n * ( x ^ ( n - 1 ) ) ) }
14
+ it 'ex1' do
15
+ $y = x ** n
16
+ expect(dy/dx).to eq( n * ( x ** ( n - 1 ) ) )
17
+ expect(d/dx($y)).to eq( n * ( x ** ( n - 1 ) ) )
20
18
  end
21
19
 
22
- context 'ex2' do
23
- let(:example) { x ^ (x * 2) }
24
- it{ expect(dy/dx).to eq(( 2 * x ) * ( x ^ ( ( 2 * x ) - 1 ) )) }
25
- it{ expect(d/dx($y)).to eq(( 2 * x ) * ( x ^ ( ( 2 * x ) - 1 ) )) }
20
+ it 'ex2' do
21
+ $y = x ** (x * 2)
22
+ expect(dy/dx).to eq(( 2 * x ) * ( x ** ( ( 2 * x ) - 1 ) ))
23
+ expect(d/dx($y)).to eq(( 2 * x ) * ( x ** ( ( 2 * x ) - 1 ) ))
26
24
  end
27
25
 
28
- context 'ex3' do
29
- let(:example) { (t ^ 2) / 2 }
30
- it{ expect(dy/dt).to eq(t) }
26
+ it 'ex3' do
27
+ $y = (t ** 2) / 2
28
+ expect(dy/dt).to eq(t)
31
29
  end
32
30
 
33
- context 'ex4' do
34
- let(:example) { 2 * (e ^ (2 * z)) }
35
- it{ expect(dy/dz).to eq(4 * ( e ^ ( 2 * z ) )) }
31
+ it 'ex4' do
32
+ $y = 2 * (e ** (2 * z))
33
+ expect(dy/dz).to eq(4 * ( e ** ( 2 * z ) ))
36
34
  end
37
35
  end