parsecs 0.11.4 → 0.11.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f31334656fdb4d48c312b6adabb100f74750060454bd21865d35594a340923af
4
- data.tar.gz: bfab768c82d4b69dcaf018b63017c1027bd648a6ca4ad036fc4a32b100f41b60
3
+ metadata.gz: eb2d58cc370e6c777c700923e4fa4bfc75bb636787a6a6cc1072d6102bc6ad96
4
+ data.tar.gz: 45081cad563cf4dec9d10da97632a69b9018676868b774151fdf43428e2910d7
5
5
  SHA512:
6
- metadata.gz: e67b9d458d4c15c4cc2dde06646ff019d9b8154b75546fb816781a92cf34c71f4d051d23b989799bba4ca0a443ed3c5b233ae4ffdb6c5c53b99e0b02583c8557
7
- data.tar.gz: bf3f8a89c3e61852edef6ce8b2489356f9681d362f6709f568969eda34575de35282df78b27cee17010a2ce562e7d9604aef28b11ab3912309e6356fcd231a67
6
+ metadata.gz: fdea60ccb0971c7434f32ac105248908a2aca0bac01ce6c3ba1608ac4d6fc0e22a4c2ecaaee0f2d8ca5fc4242d401dbc0fc176b5532bf44a9c6ec7cf330f8dfb
7
+ data.tar.gz: 461f9ce0cf4507390ecee30d31e67c827ab601e71677037ecfbaaa62ef90f9c732f1345be130f58ced14078fffa99b0e2d8c0d339decece3abd0ca6f928c5dc3
@@ -38,7 +38,7 @@ libs.each do |lib|
38
38
  end
39
39
 
40
40
  GIT_REPOSITORY = 'https://github.com/niltonvasques/equations-parser.git'.freeze
41
- COMMIT = 'd49225cddcf2fb08d8604fc2a7e6198983dcd1b9'.freeze
41
+ COMMIT = 'fe93ca5534484b05cd1eb68f7acfc32ff05dc20c'.freeze
42
42
 
43
43
  Dir.chdir(BASEDIR) do
44
44
  system('git init')
data/lib/parsec.rb CHANGED
@@ -6,7 +6,7 @@ module Parsec
6
6
  class Parsec
7
7
  using StringToBooleanRefinements
8
8
 
9
- VERSION = '0.11.4'.freeze
9
+ VERSION = '0.11.6'.freeze
10
10
 
11
11
  # evaluates the equation and returns only the result
12
12
  def self.eval_equation(equation)
@@ -49,7 +49,9 @@ module Parsec
49
49
 
50
50
  # The following regex remove all spaces that are not between quot marks
51
51
  # https://tinyurl.com/ybc7bng3
52
- equation = equation.gsub(/( |(".*?[^\\]"))/, '\\2') if new_line == true
52
+ if new_line == true
53
+ equation.gsub!(/( |("([^"\\]|\\.)*")|('([^'\\]|\\.)*'))/, '\\2')
54
+ end
53
55
 
54
56
  equation
55
57
  end
data/test/test_parsec.rb CHANGED
@@ -13,6 +13,11 @@ class TestParsec < Minitest::Test
13
13
  parser = Parsec::Parsec
14
14
  assert_equal(10, parser.eval_equation('(5 + 1) + (6 - 2)'))
15
15
  assert_equal(16, parser.eval_equation('4 + 4 * 3'))
16
+ assert_equal(604.1952, parser.eval_equation('35.52 * 17.01'))
17
+ assert_equal(404.5728, parser.eval_equation('35.52 * 11.39'))
18
+ assert_equal(634.2688, parser.eval_equation('11.84 * 53.57'))
19
+ assert_equal(423.3984, parser.eval_equation('11.84 * 35.76'))
20
+ assert_equal(309.96528, parser.eval_equation('(604.1952 + 404.5728 + 634.2688 + 423.3984) * 0.15'))
16
21
  assert_equal(2, parser.eval_equation('10.5 / 5.25'))
17
22
  assert_equal(5, parser.eval_equation('abs(-5)'))
18
23
  assert_equal(1, parser.eval_equation('log10(10)'))
@@ -25,8 +30,8 @@ class TestParsec < Minitest::Test
25
30
  def test_complex_math_equations
26
31
  parser = Parsec::Parsec
27
32
  assert_equal(6, parser.eval_equation('sqrt(16) + cbrt(8)'))
28
- assert_equal(4.30259, parser.eval_equation('log10(10) + ln(e) + log(10)'))
29
- assert_equal(2.0, parser.eval_equation('sin(1) + cos(0) + tan(0.15722)'))
33
+ assert_equal(4.30258509299405, parser.eval_equation('log10(10) + ln(e) + log(10)'))
34
+ assert_equal(1.99999931685569, parser.eval_equation('sin(1) + cos(0) + tan(0.15722)'))
30
35
  assert_equal(16, parser.eval_equation('max(1, 2) + min(3, 4) + sum(5, 6)'))
31
36
  assert_equal(9.6, parser.eval_equation('avg(9, 9.8, 10)'))
32
37
  assert_equal(8, parser.eval_equation('pow(2, 3)'))
@@ -56,6 +61,8 @@ class TestParsec < Minitest::Test
56
61
  assert_equal('TEST STRING', parser.eval_equation('toupper("test string")'))
57
62
  assert_equal('test string', parser.eval_equation('tolower("TEST STRING")'))
58
63
  assert_equal('Hello World', parser.eval_equation('concat("Hello ", "World")'))
64
+ assert_equal('Hello World', parser.eval_equation('concat("", "Hello World")'))
65
+ assert_equal('Hello World', parser.eval_equation('concat("Hello World", "")'))
59
66
  assert_equal('tes t "str \" " ing equa " tion', parser.eval_equation('concat(concat("tes t", " \\"str \\\\\" \\" ing "),string("equa \\" tion"))'))
60
67
  assert_equal(5, parser.eval_equation('str2number("5")'))
61
68
  assert_equal(5, parser.eval_equation('number("5")'))
@@ -95,7 +102,7 @@ class TestParsec < Minitest::Test
95
102
  def test_general_equations
96
103
  parsec = Parsec::Parsec
97
104
  assert_equal(1, parsec.eval_equation('((0.09/1.0)+2.58)-1.67'))
98
- assert_equal(40.6853, parsec.eval_equation('10^log(3+2)'))
105
+ assert_equal(40.6853365119738, parsec.eval_equation('10^log(3+2)'))
99
106
  assert_equal(1, parsec.eval_equation('log(e)'))
100
107
  assert_equal(2, parsec.eval_equation('2^5^0'))
101
108
  assert_equal('yes', parsec.eval_equation('5 > 3 ? "yes" : "no"'))
@@ -263,7 +270,7 @@ class TestParsec < Minitest::Test
263
270
  assert_equal({ value: 362_880_0, type: :int }, parsec.eval_equation_with_type('10!'))
264
271
  equation_date = 'daysdiff("2018-01-01", "2017-12-31")'
265
272
  assert_equal({ value: 1, type: :int }, parsec.eval_equation_with_type(equation_date))
266
- assert_equal({ value: 40.6853, type: :float }, parsec.eval_equation_with_type('10^log(3+2)'))
273
+ assert_equal({ value: 40.6853365119738, type: :float }, parsec.eval_equation_with_type('10^log(3+2)'))
267
274
  assert_equal({ value: 5.1, type: :float }, parsec.eval_equation_with_type('number("5.1")'))
268
275
  equation_if = '4 > 2 ? "bigger" : "smaller"'
269
276
  assert_equal({ value: 'bigger', type: :string }, parsec.eval_equation_with_type(equation_if))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsecs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.4
4
+ version: 0.11.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nilton Vasques
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-09-29 00:00:00.000000000 Z
13
+ date: 2022-11-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: minitest