factbase 0.0.59 → 0.1.0

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: c62bd0cae1b70119954f0f2c1eef5ef9ff92e7073dc5f86492cc1f048456580c
4
- data.tar.gz: 7cfd0410d94217f51b84e41707c1bfecd493f022a840507f18a2d92fd9bb3d9c
3
+ metadata.gz: 190cce930c1b89f0b8f9a3f5bfd1c186b0fcb44b237056c89c0844d3ded39102
4
+ data.tar.gz: 900c8db8d5d4b6494c409d9df9b0acf9e484a4e680dce67df31ab754e0c1ddc6
5
5
  SHA512:
6
- metadata.gz: 46d98f86cc24e7ca8db4c543fe34080c2571009e0715699be377fdd4a4589d0a99165c9d45ae2e2fbc432d2592231be7122d0c1c45bc77c5d351c497d1fee703
7
- data.tar.gz: d8f0f6e49e6d5c7740f3d70f46860a425f1f9de3a91bdf927cec4579f87aac4357e5e0a6e148d7d9d58ed34a99ddc1ad57c40c0018e735110083f30a594d1ee4
6
+ metadata.gz: b78e198034d25412f97a07273c3005bf0f10b14e5889370f48e7ac687f16e3bb708393d10bebe00289db0f1f478d9de2eb7f2be2d58a6d5dcedbda1438444a8a
7
+ data.tar.gz: 5d66f9d6d94c48ad3de475d7bf478b6cd133c15598d1a8a17bf53a8467e03631737e4ae345826972d6158df4f2f315102a7743453ba031a3d6d64110de6ef1da
@@ -27,4 +27,4 @@ jobs:
27
27
  runs-on: ubuntu-22.04
28
28
  steps:
29
29
  - uses: actions/checkout@v4
30
- - uses: yegor256/copyrights-action@0.0.4
30
+ - uses: yegor256/copyrights-action@0.0.5
data/Gemfile CHANGED
@@ -24,11 +24,12 @@ source 'https://rubygems.org'
24
24
  gemspec
25
25
 
26
26
  gem 'minitest', '5.24.1', require: false
27
+ gem 'minitest-reporters', '1.7.1', require: false
27
28
  gem 'rake', '13.2.1', require: false
28
29
  gem 'rspec-rails', '6.1.3', require: false
29
- gem 'rubocop', '1.64.1', require: false
30
+ gem 'rubocop', '1.65.0', require: false
30
31
  gem 'rubocop-performance', '1.21.1', require: false
31
- gem 'rubocop-rspec', '3.0.1', require: false
32
+ gem 'rubocop-rspec', '3.0.3', require: false
32
33
  gem 'simplecov', '0.22.0', require: false
33
34
  gem 'simplecov-cobertura', '2.1.0', require: false
34
35
  gem 'yard', '0.9.36', require: false
data/Gemfile.lock CHANGED
@@ -40,6 +40,7 @@ GEM
40
40
  minitest (>= 5.1)
41
41
  mutex_m
42
42
  tzinfo (~> 2.0)
43
+ ansi (1.5.0)
43
44
  ast (2.4.2)
44
45
  backtrace (0.4.0)
45
46
  base64 (0.2.0)
@@ -56,7 +57,7 @@ GEM
56
57
  i18n (1.14.5)
57
58
  concurrent-ruby (~> 1.0)
58
59
  io-console (0.7.2)
59
- irb (1.13.2)
60
+ irb (1.14.0)
60
61
  rdoc (>= 4.0.0)
61
62
  reline (>= 0.4.2)
62
63
  json (2.7.2)
@@ -66,6 +67,11 @@ GEM
66
67
  nokogiri (>= 1.12.0)
67
68
  loog (0.5.2)
68
69
  minitest (5.24.1)
70
+ minitest-reporters (1.7.1)
71
+ ansi
72
+ builder
73
+ minitest (>= 5.0)
74
+ ruby-progressbar
69
75
  mutex_m (0.2.0)
70
76
  nokogiri (1.16.6-arm64-darwin)
71
77
  racc (~> 1.4)
@@ -77,13 +83,13 @@ GEM
77
83
  racc (~> 1.4)
78
84
  others (0.0.3)
79
85
  parallel (1.25.1)
80
- parser (3.3.3.0)
86
+ parser (3.3.4.0)
81
87
  ast (~> 2.4.1)
82
88
  racc
83
89
  psych (5.1.2)
84
90
  stringio
85
91
  racc (1.8.0)
86
- rack (3.1.4)
92
+ rack (3.1.7)
87
93
  rack-session (2.0.0)
88
94
  rack (>= 3.0.0)
89
95
  rack-test (2.1.0)
@@ -113,7 +119,7 @@ GEM
113
119
  regexp_parser (2.9.2)
114
120
  reline (0.5.9)
115
121
  io-console (~> 0.5)
116
- rexml (3.3.1)
122
+ rexml (3.3.2)
117
123
  strscan
118
124
  rspec-core (3.13.0)
119
125
  rspec-support (~> 3.13.0)
@@ -132,13 +138,13 @@ GEM
132
138
  rspec-mocks (~> 3.13)
133
139
  rspec-support (~> 3.13)
134
140
  rspec-support (3.13.1)
135
- rubocop (1.64.1)
141
+ rubocop (1.65.0)
136
142
  json (~> 2.3)
137
143
  language_server-protocol (>= 3.17.0)
138
144
  parallel (~> 1.10)
139
145
  parser (>= 3.3.0.2)
140
146
  rainbow (>= 2.2.2, < 4.0)
141
- regexp_parser (>= 1.8, < 3.0)
147
+ regexp_parser (>= 2.4, < 3.0)
142
148
  rexml (>= 3.2.5, < 4.0)
143
149
  rubocop-ast (>= 1.31.1, < 2.0)
144
150
  ruby-progressbar (~> 1.7)
@@ -148,7 +154,7 @@ GEM
148
154
  rubocop-performance (1.21.1)
149
155
  rubocop (>= 1.48.1, < 2.0)
150
156
  rubocop-ast (>= 1.31.1, < 2.0)
151
- rubocop-rspec (3.0.1)
157
+ rubocop-rspec (3.0.3)
152
158
  rubocop (~> 1.61)
153
159
  ruby-progressbar (1.13.0)
154
160
  simplecov (0.22.0)
@@ -181,11 +187,12 @@ PLATFORMS
181
187
  DEPENDENCIES
182
188
  factbase!
183
189
  minitest (= 5.24.1)
190
+ minitest-reporters (= 1.7.1)
184
191
  rake (= 13.2.1)
185
192
  rspec-rails (= 6.1.3)
186
- rubocop (= 1.64.1)
193
+ rubocop (= 1.65.0)
187
194
  rubocop-performance (= 1.21.1)
188
- rubocop-rspec (= 3.0.1)
195
+ rubocop-rspec (= 3.0.3)
189
196
  simplecov (= 0.22.0)
190
197
  simplecov-cobertura (= 2.1.0)
191
198
  yard (= 0.9.36)
data/factbase.gemspec CHANGED
@@ -42,13 +42,13 @@ Gem::Specification.new do |s|
42
42
  s.files = `git ls-files`.split($RS)
43
43
  s.rdoc_options = ['--charset=UTF-8']
44
44
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
45
- s.add_runtime_dependency 'backtrace', '~>0.3'
46
- s.add_runtime_dependency 'decoor', '~>0.0'
47
- s.add_runtime_dependency 'json', '~>2.7'
48
- s.add_runtime_dependency 'loog', '~>0.2'
49
- s.add_runtime_dependency 'nokogiri', '~>1.10'
50
- s.add_runtime_dependency 'others', '~>0.0'
51
- s.add_runtime_dependency 'tago', '~>0.0'
52
- s.add_runtime_dependency 'yaml', '~>0.3'
45
+ s.add_dependency 'backtrace', '~>0.3'
46
+ s.add_dependency 'decoor', '~>0.0'
47
+ s.add_dependency 'json', '~>2.7'
48
+ s.add_dependency 'loog', '~>0.2'
49
+ s.add_dependency 'nokogiri', '~>1.10'
50
+ s.add_dependency 'others', '~>0.0'
51
+ s.add_dependency 'tago', '~>0.0'
52
+ s.add_dependency 'yaml', '~>0.3'
53
53
  s.metadata['rubygems_mfa_required'] = 'true'
54
54
  end
@@ -35,8 +35,10 @@ require_relative 'term'
35
35
  class Factbase::Syntax
36
36
  # Ctor.
37
37
  # @param [String] query The query, for example "(eq id 42)"
38
- def initialize(query)
38
+ # @param [Class] term The class to instantiate to make every term
39
+ def initialize(query, term: Factbase::Term)
39
40
  @query = query
41
+ @term = term
40
42
  end
41
43
 
42
44
  # Convert it to a term.
@@ -60,7 +62,7 @@ class Factbase::Syntax
60
62
  raise 'Too many terms' if @ast[1] != @tokens.size
61
63
  term = @ast[0]
62
64
  raise 'No terms found' if term.nil?
63
- raise 'Not a term' unless term.is_a?(Factbase::Term)
65
+ raise 'Not a term' unless term.is_a?(@term)
64
66
  term
65
67
  end
66
68
 
@@ -89,7 +91,7 @@ class Factbase::Syntax
89
91
  operands << operand
90
92
  break if tokens[at] == :close
91
93
  end
92
- [Factbase::Term.new(op, operands), at + 1]
94
+ [@term.new(op, operands), at + 1]
93
95
  end
94
96
 
95
97
  # Turns a query into an array of tokens.
data/lib/factbase/term.rb CHANGED
@@ -130,13 +130,6 @@ class Factbase::Term
130
130
 
131
131
  private
132
132
 
133
- def either(fact, maps)
134
- assert_args(2)
135
- v = the_values(0, fact, maps)
136
- return v unless v.nil?
137
- the_values(1, fact, maps)
138
- end
139
-
140
133
  def at(fact, maps)
141
134
  assert_args(2)
142
135
  i = the_values(0, fact, maps)
@@ -57,6 +57,20 @@ module Factbase::Term::Logical
57
57
  true
58
58
  end
59
59
 
60
+ def when(fact, maps)
61
+ assert_args(2)
62
+ a = @operands[0]
63
+ b = @operands[1]
64
+ !a.evaluate(fact, maps) || (a.evaluate(fact, maps) && b.evaluate(fact, maps))
65
+ end
66
+
67
+ def either(fact, maps)
68
+ assert_args(2)
69
+ v = the_values(0, fact, maps)
70
+ return v unless v.nil?
71
+ the_values(1, fact, maps)
72
+ end
73
+
60
74
  def and_or_simplify
61
75
  strs = []
62
76
  ops = []
@@ -79,13 +93,6 @@ module Factbase::Term::Logical
79
93
  and_or_simplify
80
94
  end
81
95
 
82
- def when(fact, maps)
83
- assert_args(2)
84
- a = @operands[0]
85
- b = @operands[1]
86
- !a.evaluate(fact, maps) || (a.evaluate(fact, maps) && b.evaluate(fact, maps))
87
- end
88
-
89
96
  def _only_bool(val, pos)
90
97
  val = val[0] if val.is_a?(Array)
91
98
  return false if val.nil?
@@ -29,12 +29,12 @@ require_relative '../../factbase'
29
29
  # License:: MIT
30
30
  module Factbase::Term::Strings
31
31
  def concat(fact, maps)
32
- (0..@operands.length - 1).map { |i| the_values(i, fact, maps)[0] }.join
32
+ (0..@operands.length - 1).map { |i| the_values(i, fact, maps)&.first }.join
33
33
  end
34
34
 
35
35
  def sprintf(fact, maps)
36
36
  fmt = the_values(0, fact, maps)[0]
37
- ops = (1..@operands.length - 1).map { |i| the_values(i, fact, maps)[0] }
37
+ ops = (1..@operands.length - 1).map { |i| the_values(i, fact, maps)&.first }
38
38
  format(*([fmt] + ops))
39
39
  end
40
40
 
data/lib/factbase.rb CHANGED
@@ -81,7 +81,7 @@ require 'yaml'
81
81
  # License:: MIT
82
82
  class Factbase
83
83
  # Current version of the gem (changed by .rultor.yml on every release)
84
- VERSION = '0.0.59'
84
+ VERSION = '0.1.0'
85
85
 
86
86
  # An exception that may be thrown in a transaction, to roll it back.
87
87
  class Rollback < StandardError; end
@@ -99,7 +99,7 @@ class Factbase
99
99
  Factbase.new(@maps.map { |m| m.transform_values(&:dup) })
100
100
  end
101
101
 
102
- # Size.
102
+ # Size, the total number of facts in the factbase.
103
103
  # @return [Integer] How many facts are in there
104
104
  def size
105
105
  @maps.size
@@ -114,11 +114,11 @@ class Factbase
114
114
  #
115
115
  # @return [Factbase::Fact] The fact just inserted
116
116
  def insert
117
- require_relative 'factbase/fact'
118
117
  map = {}
119
118
  @mutex.synchronize do
120
119
  @maps << map
121
120
  end
121
+ require_relative 'factbase/fact'
122
122
  Factbase::Fact.new(@mutex, map)
123
123
  end
124
124
 
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2024 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'minitest/autorun'
24
+ require_relative '../../../lib/factbase/term'
25
+
26
+ # Defn test.
27
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
29
+ # License:: MIT
30
+ class TestDefn < Minitest::Test
31
+ def test_defn_simple
32
+ t = Factbase::Term.new(:defn, [:foo, 'self.to_s'])
33
+ assert_equal(true, t.evaluate(fact('foo' => 4), []))
34
+ t1 = Factbase::Term.new(:foo, ['hello, world!'])
35
+ assert_equal('(foo \'hello, world!\')', t1.evaluate(fact, []))
36
+ end
37
+
38
+ def test_defn_again_by_mistake
39
+ t = Factbase::Term.new(:defn, [:and, 'self.to_s'])
40
+ assert_raises do
41
+ t.evaluate(fact, [])
42
+ end
43
+ end
44
+
45
+ def test_defn_bad_name_by_mistake
46
+ t = Factbase::Term.new(:defn, [:to_s, 'self.to_s'])
47
+ assert_raises do
48
+ t.evaluate(fact, [])
49
+ end
50
+ end
51
+
52
+ def test_defn_bad_name_spelling_by_mistake
53
+ t = Factbase::Term.new(:defn, [:'some-key', 'self.to_s'])
54
+ assert_raises do
55
+ t.evaluate(fact, [])
56
+ end
57
+ end
58
+
59
+ def test_undef_simple
60
+ t = Factbase::Term.new(:defn, [:hello, 'self.to_s'])
61
+ assert_equal(true, t.evaluate(fact, []))
62
+ t = Factbase::Term.new(:undef, [:hello])
63
+ assert_equal(true, t.evaluate(fact, []))
64
+ end
65
+
66
+ private
67
+
68
+ def fact(map = {})
69
+ Factbase::Fact.new(Mutex.new, map)
70
+ end
71
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2024 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'minitest/autorun'
24
+ require_relative '../../../lib/factbase/term'
25
+
26
+ # Logical test.
27
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
29
+ # License:: MIT
30
+ class TestLogical < Minitest::Test
31
+ def test_not_matching
32
+ t = Factbase::Term.new(:not, [Factbase::Term.new(:always, [])])
33
+ assert(!t.evaluate(fact('foo' => [100]), []))
34
+ end
35
+
36
+ def test_not_eq_matching
37
+ t = Factbase::Term.new(:not, [Factbase::Term.new(:eq, [:foo, 100])])
38
+ assert(t.evaluate(fact('foo' => [42, 12, -90]), []))
39
+ assert(!t.evaluate(fact('foo' => 100), []))
40
+ end
41
+
42
+ def test_either
43
+ t = Factbase::Term.new(:either, [Factbase::Term.new(:at, [5, :foo]), 42])
44
+ assert_equal([42], t.evaluate(fact('foo' => 4), []))
45
+ end
46
+
47
+ def test_or_matching
48
+ t = Factbase::Term.new(
49
+ :or,
50
+ [
51
+ Factbase::Term.new(:eq, [:foo, 4]),
52
+ Factbase::Term.new(:eq, [:bar, 5])
53
+ ]
54
+ )
55
+ assert(t.evaluate(fact('foo' => [4]), []))
56
+ assert(t.evaluate(fact('bar' => [5]), []))
57
+ assert(!t.evaluate(fact('bar' => [42]), []))
58
+ end
59
+
60
+ def test_when_matching
61
+ t = Factbase::Term.new(
62
+ :when,
63
+ [
64
+ Factbase::Term.new(:eq, [:foo, 4]),
65
+ Factbase::Term.new(:eq, [:bar, 5])
66
+ ]
67
+ )
68
+ assert(t.evaluate(fact('foo' => 4, 'bar' => 5), []))
69
+ assert(!t.evaluate(fact('foo' => 4), []))
70
+ assert(t.evaluate(fact('foo' => 5, 'bar' => 5), []))
71
+ end
72
+
73
+ private
74
+
75
+ def fact(map = {})
76
+ Factbase::Fact.new(Mutex.new, map)
77
+ end
78
+ end
@@ -106,6 +106,12 @@ class TestMath < Minitest::Test
106
106
  assert_equal('Float', t.evaluate(fact, []).class.to_s)
107
107
  end
108
108
 
109
+ def test_plus
110
+ t = Factbase::Term.new(:plus, [:foo, 42])
111
+ assert_equal(46, t.evaluate(fact('foo' => 4), []))
112
+ assert(t.evaluate(fact, []).nil?)
113
+ end
114
+
109
115
  private
110
116
 
111
117
  def fact(map = {})
@@ -28,9 +28,17 @@ require_relative '../../../lib/factbase/term'
28
28
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
29
29
  # License:: MIT
30
30
  class TestStrings < Minitest::Test
31
+ def test_regexp_matching
32
+ t = Factbase::Term.new(:matches, [:foo, '[a-z]+'])
33
+ assert(t.evaluate(fact('foo' => 'hello'), []))
34
+ assert(t.evaluate(fact('foo' => 'hello 42'), []))
35
+ assert(!t.evaluate(fact('foo' => 42), []))
36
+ end
37
+
31
38
  def test_concat
32
- t = Factbase::Term.new(:concat, [42, 'hi', 3.14, Time.now])
33
- assert(t.evaluate(fact, []).start_with?('42hi3.14'))
39
+ t = Factbase::Term.new(:concat, [42, 'hi', 3.14, :hey, Time.now])
40
+ s = t.evaluate(fact, [])
41
+ assert(s.start_with?('42hi3.14'), s)
34
42
  end
35
43
 
36
44
  def test_concat_empty
@@ -120,8 +120,13 @@ class TestQuery < Minitest::Test
120
120
  '(agg (always) (count))' => 2,
121
121
  '(agg (eq bar $v) (count))' => 1,
122
122
  '(agg (eq z 40) (count))' => 0
123
- }.each do |q, r|
124
- assert_equal(r, Factbase::Query.new(maps, Mutex.new, q).one(v: 4), "#{q} -> #{r}")
123
+ }.each do |q, expected|
124
+ result = Factbase::Query.new(maps, Mutex.new, q).one(v: 4)
125
+ if expected.nil?
126
+ assert_nil(result, "#{q} -> nil")
127
+ else
128
+ assert_equal(expected, result, "#{q} -> #{expected}")
129
+ end
125
130
  end
126
131
  end
127
132
 
@@ -33,17 +33,6 @@ class TestTerm < Minitest::Test
33
33
  assert(!t.evaluate(fact('foo' => [100]), []))
34
34
  end
35
35
 
36
- def test_not_matching
37
- t = Factbase::Term.new(:not, [Factbase::Term.new(:always, [])])
38
- assert(!t.evaluate(fact('foo' => [100]), []))
39
- end
40
-
41
- def test_not_eq_matching
42
- t = Factbase::Term.new(:not, [Factbase::Term.new(:eq, [:foo, 100])])
43
- assert(t.evaluate(fact('foo' => [42, 12, -90]), []))
44
- assert(!t.evaluate(fact('foo' => 100), []))
45
- end
46
-
47
36
  def test_size_matching
48
37
  t = Factbase::Term.new(:size, [:foo])
49
38
  assert_equal(3, t.evaluate(fact('foo' => [42, 12, -90]), []))
@@ -74,74 +63,6 @@ class TestTerm < Minitest::Test
74
63
  assert_equal('nil', t.evaluate(fact, []))
75
64
  end
76
65
 
77
- def test_regexp_matching
78
- t = Factbase::Term.new(:matches, [:foo, '[a-z]+'])
79
- assert(t.evaluate(fact('foo' => 'hello'), []))
80
- assert(t.evaluate(fact('foo' => 'hello 42'), []))
81
- assert(!t.evaluate(fact('foo' => 42), []))
82
- end
83
-
84
- def test_or_matching
85
- t = Factbase::Term.new(
86
- :or,
87
- [
88
- Factbase::Term.new(:eq, [:foo, 4]),
89
- Factbase::Term.new(:eq, [:bar, 5])
90
- ]
91
- )
92
- assert(t.evaluate(fact('foo' => [4]), []))
93
- assert(t.evaluate(fact('bar' => [5]), []))
94
- assert(!t.evaluate(fact('bar' => [42]), []))
95
- end
96
-
97
- def test_when_matching
98
- t = Factbase::Term.new(
99
- :when,
100
- [
101
- Factbase::Term.new(:eq, [:foo, 4]),
102
- Factbase::Term.new(:eq, [:bar, 5])
103
- ]
104
- )
105
- assert(t.evaluate(fact('foo' => 4, 'bar' => 5), []))
106
- assert(!t.evaluate(fact('foo' => 4), []))
107
- assert(t.evaluate(fact('foo' => 5, 'bar' => 5), []))
108
- end
109
-
110
- def test_defn_simple
111
- t = Factbase::Term.new(:defn, [:foo, 'self.to_s'])
112
- assert_equal(true, t.evaluate(fact('foo' => 4), []))
113
- t1 = Factbase::Term.new(:foo, ['hello, world!'])
114
- assert_equal('(foo \'hello, world!\')', t1.evaluate(fact, []))
115
- end
116
-
117
- def test_defn_again_by_mistake
118
- t = Factbase::Term.new(:defn, [:and, 'self.to_s'])
119
- assert_raises do
120
- t.evaluate(fact, [])
121
- end
122
- end
123
-
124
- def test_defn_bad_name_by_mistake
125
- t = Factbase::Term.new(:defn, [:to_s, 'self.to_s'])
126
- assert_raises do
127
- t.evaluate(fact, [])
128
- end
129
- end
130
-
131
- def test_defn_bad_name_spelling_by_mistake
132
- t = Factbase::Term.new(:defn, [:'some-key', 'self.to_s'])
133
- assert_raises do
134
- t.evaluate(fact, [])
135
- end
136
- end
137
-
138
- def test_undef_simple
139
- t = Factbase::Term.new(:defn, [:hello, 'self.to_s'])
140
- assert_equal(true, t.evaluate(fact, []))
141
- t = Factbase::Term.new(:undef, [:hello])
142
- assert_equal(true, t.evaluate(fact, []))
143
- end
144
-
145
66
  def test_past
146
67
  t = Factbase::Term.new(:prev, [:foo])
147
68
  assert_nil(t.evaluate(fact('foo' => 4), []))
@@ -154,17 +75,6 @@ class TestTerm < Minitest::Test
154
75
  assert_equal(5, t.evaluate(fact('foo' => [4, 5]), []))
155
76
  end
156
77
 
157
- def test_either
158
- t = Factbase::Term.new(:either, [Factbase::Term.new(:at, [5, :foo]), 42])
159
- assert_equal([42], t.evaluate(fact('foo' => 4), []))
160
- end
161
-
162
- def test_plus
163
- t = Factbase::Term.new(:plus, [:foo, 42])
164
- assert_equal(46, t.evaluate(fact('foo' => 4), []))
165
- assert(t.evaluate(fact, []).nil?)
166
- end
167
-
168
78
  def test_report_missing_term
169
79
  t = Factbase::Term.new(:something, [])
170
80
  msg = assert_raises do
data/test/test__helper.rb CHANGED
@@ -29,3 +29,6 @@ require 'simplecov-cobertura'
29
29
  SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
30
30
 
31
31
  require 'minitest/autorun'
32
+
33
+ require 'minitest/reporters'
34
+ Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.59
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-02 00:00:00.000000000 Z
11
+ date: 2024-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -183,6 +183,8 @@ files:
183
183
  - renovate.json
184
184
  - test/factbase/terms/test_aggregates.rb
185
185
  - test/factbase/terms/test_aliases.rb
186
+ - test/factbase/terms/test_defn.rb
187
+ - test/factbase/terms/test_logical.rb
186
188
  - test/factbase/terms/test_math.rb
187
189
  - test/factbase/terms/test_strings.rb
188
190
  - test/factbase/test_accum.rb