dentaku 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dentaku/evaluator.rb +4 -0
- data/lib/dentaku/rules.rb +3 -1
- data/lib/dentaku/version.rb +1 -1
- data/spec/calculator_spec.rb +2 -0
- data/spec/evaluator_spec.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b6c2a647d615b07bb92995438da601259cb87f3
|
|
4
|
+
data.tar.gz: 75c685525c0eb619726c0d03ded7401573eaaf33
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7035e118512d9c98dbcc31cb510358e8ca5fee3b98b9bb2242671a7ede8c8ae0c1e4028869367615b9c91a9ff82cece3c13e70032547ef432539c9d0b8986be1
|
|
7
|
+
data.tar.gz: fb40309c2d88b7036462a4acb372753350b6655a519fa165a0f534a5464a50088cd53aa908c33e59c06bb957e69305190bd33361805d6346961c8a04126a39a7
|
data/lib/dentaku/evaluator.rb
CHANGED
|
@@ -102,6 +102,10 @@ module Dentaku
|
|
|
102
102
|
Token.new(base.category, base.value ** (exp.value * -1))
|
|
103
103
|
end
|
|
104
104
|
|
|
105
|
+
def mul_negate(val1, _, _, val2)
|
|
106
|
+
Token.new(val1.category, val1.value * val2.value * -1)
|
|
107
|
+
end
|
|
108
|
+
|
|
105
109
|
def percentage(token, _)
|
|
106
110
|
Token.new(token.category, token.value / 100.0)
|
|
107
111
|
end
|
data/lib/dentaku/rules.rb
CHANGED
|
@@ -18,6 +18,7 @@ module Dentaku
|
|
|
18
18
|
[ p(:math_neg_pow), :pow_negate ],
|
|
19
19
|
[ p(:math_mod), :apply ],
|
|
20
20
|
[ p(:math_mul), :apply ],
|
|
21
|
+
[ p(:math_neg_mul), :mul_negate ],
|
|
21
22
|
[ p(:math_add), :apply ],
|
|
22
23
|
[ p(:percentage), :percentage ],
|
|
23
24
|
[ p(:negation), :negate ],
|
|
@@ -69,7 +70,7 @@ module Dentaku
|
|
|
69
70
|
:comparator, :comp_gt, :comp_lt, :fopen, :open, :close, :comma,
|
|
70
71
|
:non_close_plus, :non_group, :non_group_star, :arguments,
|
|
71
72
|
:logical, :combinator, :if, :round, :roundup, :rounddown, :not,
|
|
72
|
-
:anchored_minus, :math_neg_pow
|
|
73
|
+
:anchored_minus, :math_neg_pow, :math_neg_mul
|
|
73
74
|
].each_with_object({}) do |name, matchers|
|
|
74
75
|
matchers[name] = TokenMatcher.send(name)
|
|
75
76
|
end
|
|
@@ -80,6 +81,7 @@ module Dentaku
|
|
|
80
81
|
group: pattern(:open, :non_group_star, :close),
|
|
81
82
|
math_add: pattern(:numeric, :addsub, :numeric),
|
|
82
83
|
math_mul: pattern(:numeric, :muldiv, :numeric),
|
|
84
|
+
math_neg_mul: pattern(:numeric, :muldiv, :subtract, :numeric),
|
|
83
85
|
math_pow: pattern(:numeric, :pow, :numeric),
|
|
84
86
|
math_neg_pow: pattern(:numeric, :pow, :subtract, :numeric),
|
|
85
87
|
math_mod: pattern(:numeric, :mod, :numeric),
|
data/lib/dentaku/version.rb
CHANGED
data/spec/calculator_spec.rb
CHANGED
|
@@ -24,6 +24,8 @@ describe Dentaku::Calculator do
|
|
|
24
24
|
expect(calculator.evaluate('-num + 3', :num => 2)).to eq(1)
|
|
25
25
|
expect(calculator.evaluate('10 ^ 2')).to eq(100)
|
|
26
26
|
expect(calculator.evaluate('0 * 10 ^ -5')).to eq(0)
|
|
27
|
+
expect(calculator.evaluate('3 + 0 * -3')).to eq(3)
|
|
28
|
+
expect(calculator.evaluate('3 + 0 / -3')).to eq(3)
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
describe 'memory' do
|
data/spec/evaluator_spec.rb
CHANGED
|
@@ -46,6 +46,7 @@ describe Dentaku::Evaluator do
|
|
|
46
46
|
expect(evaluator.evaluate(token_stream(1, :subtract, :subtract, 1))).to eq(2)
|
|
47
47
|
expect(evaluator.evaluate(token_stream(1, :subtract, :subtract, :subtract, 1))).to eq(0)
|
|
48
48
|
expect(evaluator.evaluate(token_stream(:subtract, 1, :add, 1))).to eq(0)
|
|
49
|
+
expect(evaluator.evaluate(token_stream(3, :add, 0, :multiply, :subtract, 3))).to eq(3)
|
|
49
50
|
end
|
|
50
51
|
|
|
51
52
|
it 'evaluates a number multiplied by an exponent' do
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dentaku
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Solomon White
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|