factbase 0.7.3 → 0.7.5
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/.github/workflows/benchmark.yml +3 -1
- data/.gitignore +6 -5
- data/.rultor.yml +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +9 -9
- data/README.md +37 -25
- data/REUSE.toml +4 -0
- data/Rakefile +10 -3
- data/benchmark/bench_factbase.rb +61 -0
- data/benchmark/bench_large_query.rb +128 -0
- data/benchmark/bench_query.rb +41 -0
- data/benchmark/bench_taped.rb +33 -0
- data/factbase.gemspec +5 -5
- data/lib/factbase/accum.rb +1 -1
- data/lib/factbase/{looged.rb → logged.rb} +8 -8
- data/lib/factbase/taped.rb +25 -25
- data/lib/factbase/term.rb +9 -1
- data/lib/factbase/terms/aggregates.rb +2 -2
- data/lib/factbase/terms/meta.rb +1 -1
- data/lib/factbase/terms/ordering.rb +1 -1
- data/lib/factbase.rb +3 -5
- data/test/factbase/terms/test_aggregates.rb +2 -2
- data/test/factbase/terms/test_aliases.rb +4 -4
- data/test/factbase/terms/test_casting.rb +1 -2
- data/test/factbase/terms/test_debug.rb +2 -2
- data/test/factbase/terms/test_defn.rb +2 -2
- data/test/factbase/terms/test_logical.rb +2 -2
- data/test/factbase/terms/test_math.rb +1 -2
- data/test/factbase/terms/test_meta.rb +2 -2
- data/test/factbase/terms/test_ordering.rb +2 -2
- data/test/factbase/terms/test_strings.rb +2 -2
- data/test/factbase/terms/test_system.rb +1 -2
- data/test/factbase/test_accum.rb +2 -2
- data/test/factbase/test_churn.rb +2 -2
- data/test/factbase/test_fact.rb +2 -2
- data/test/factbase/test_flatten.rb +2 -2
- data/test/factbase/test_inv.rb +2 -2
- data/test/factbase/{test_looged.rb → test_logged.rb} +13 -13
- data/test/factbase/test_pre.rb +2 -2
- data/test/factbase/test_query.rb +2 -2
- data/test/factbase/test_rules.rb +2 -2
- data/test/factbase/test_syntax.rb +2 -2
- data/test/factbase/test_tallied.rb +2 -2
- data/test/factbase/test_taped.rb +2 -2
- data/test/factbase/test_tee.rb +2 -2
- data/test/factbase/test_term.rb +2 -2
- data/test/factbase/test_to_json.rb +2 -2
- data/test/factbase/test_to_xml.rb +2 -2
- data/test/factbase/test_to_yaml.rb +2 -2
- data/test/test__helper.rb +3 -1
- data/test/test_factbase.rb +5 -5
- metadata +29 -29
- data/benchmarks/simple.rb +0 -127
data/lib/factbase/taped.rb
CHANGED
|
@@ -12,20 +12,27 @@ require_relative '../factbase'
|
|
|
12
12
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
13
13
|
# License:: MIT
|
|
14
14
|
class Factbase::Taped
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def initialize(origin, lookup: {})
|
|
15
|
+
def initialize(origin)
|
|
18
16
|
@origin = origin
|
|
19
|
-
@inserted =
|
|
20
|
-
@deleted =
|
|
21
|
-
@added =
|
|
22
|
-
|
|
17
|
+
@inserted = []
|
|
18
|
+
@deleted = []
|
|
19
|
+
@added = []
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def inserted
|
|
23
|
+
@inserted.uniq
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def deleted
|
|
27
|
+
@deleted.uniq
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def added
|
|
31
|
+
@added.uniq
|
|
23
32
|
end
|
|
24
33
|
|
|
25
34
|
def find_by_object_id(oid)
|
|
26
|
-
|
|
27
|
-
o = @origin.find { |m| m.object_id == oid } if o.nil?
|
|
28
|
-
o
|
|
35
|
+
@origin.find { |m| m.object_id == oid }
|
|
29
36
|
end
|
|
30
37
|
|
|
31
38
|
def size
|
|
@@ -34,17 +41,12 @@ class Factbase::Taped
|
|
|
34
41
|
|
|
35
42
|
def <<(map)
|
|
36
43
|
@origin << (map)
|
|
37
|
-
|
|
38
|
-
@lookup[map.object_id] = map
|
|
39
|
-
# rubocop:enable Lint/HashCompareByIdentity
|
|
40
|
-
@inserted.add(map.object_id)
|
|
44
|
+
@inserted.append(map.object_id)
|
|
41
45
|
end
|
|
42
46
|
|
|
43
47
|
def each
|
|
48
|
+
return to_enum(__method__) unless block_given?
|
|
44
49
|
@origin.each do |m|
|
|
45
|
-
# rubocop:disable Lint/HashCompareByIdentity
|
|
46
|
-
@lookup[m.object_id] = m
|
|
47
|
-
# rubocop:enable Lint/HashCompareByIdentity
|
|
48
50
|
yield TapedHash.new(m, @added)
|
|
49
51
|
end
|
|
50
52
|
end
|
|
@@ -52,10 +54,7 @@ class Factbase::Taped
|
|
|
52
54
|
def delete_if
|
|
53
55
|
@origin.delete_if do |m|
|
|
54
56
|
r = yield m
|
|
55
|
-
if r
|
|
56
|
-
@lookup.delete(m.object_id)
|
|
57
|
-
@deleted.add(m.object_id)
|
|
58
|
-
end
|
|
57
|
+
@deleted.append(m.object_id) if r
|
|
59
58
|
r
|
|
60
59
|
end
|
|
61
60
|
end
|
|
@@ -69,13 +68,13 @@ class Factbase::Taped
|
|
|
69
68
|
|
|
70
69
|
def [](key)
|
|
71
70
|
v = @origin[key]
|
|
72
|
-
v = TapedArray.new(v, @origin.object_id, @added) if v.
|
|
71
|
+
v = TapedArray.new(v, @origin.object_id, @added) if v.is_a?(Array)
|
|
73
72
|
v
|
|
74
73
|
end
|
|
75
74
|
|
|
76
75
|
def []=(key, value)
|
|
77
76
|
@origin[key] = value
|
|
78
|
-
@added.
|
|
77
|
+
@added.append(@origin.object_id)
|
|
79
78
|
end
|
|
80
79
|
end
|
|
81
80
|
|
|
@@ -88,6 +87,7 @@ class Factbase::Taped
|
|
|
88
87
|
end
|
|
89
88
|
|
|
90
89
|
def each(&)
|
|
90
|
+
return to_enum(__method__) unless block_given?
|
|
91
91
|
@origin.each(&)
|
|
92
92
|
end
|
|
93
93
|
|
|
@@ -104,12 +104,12 @@ class Factbase::Taped
|
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
def <<(item)
|
|
107
|
-
@added.
|
|
107
|
+
@added.append(@oid)
|
|
108
108
|
@origin << (item)
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
def uniq!
|
|
112
|
-
@added.
|
|
112
|
+
@added.append(@oid)
|
|
113
113
|
@origin.uniq!
|
|
114
114
|
end
|
|
115
115
|
end
|
data/lib/factbase/term.rb
CHANGED
|
@@ -172,12 +172,20 @@ class Factbase::Term
|
|
|
172
172
|
fact[k]
|
|
173
173
|
end
|
|
174
174
|
|
|
175
|
+
# @return [Array|nil] Either array of values or NIL
|
|
175
176
|
def the_values(pos, fact, maps)
|
|
176
177
|
v = @operands[pos]
|
|
177
178
|
v = v.evaluate(fact, maps) if v.is_a?(Factbase::Term)
|
|
178
179
|
v = fact[v.to_s] if v.is_a?(Symbol)
|
|
179
180
|
return v if v.nil?
|
|
180
|
-
|
|
181
|
+
unless v.is_a?(Array)
|
|
182
|
+
v =
|
|
183
|
+
if v.respond_to?(:each)
|
|
184
|
+
v.to_a
|
|
185
|
+
else
|
|
186
|
+
[v]
|
|
187
|
+
end
|
|
188
|
+
end
|
|
181
189
|
v
|
|
182
190
|
end
|
|
183
191
|
end
|
|
@@ -50,7 +50,7 @@ module Factbase::Term::Aggregates
|
|
|
50
50
|
maps.each do |m|
|
|
51
51
|
vv = m[k.to_s]
|
|
52
52
|
next if vv.nil?
|
|
53
|
-
vv = [vv] unless vv.respond_to?(:
|
|
53
|
+
vv = [vv] unless vv.respond_to?(:to_a)
|
|
54
54
|
vv.each do |v|
|
|
55
55
|
sum += v
|
|
56
56
|
end
|
|
@@ -82,7 +82,7 @@ module Factbase::Term::Aggregates
|
|
|
82
82
|
maps.each do |m|
|
|
83
83
|
vv = m[k.to_s]
|
|
84
84
|
next if vv.nil?
|
|
85
|
-
vv = [vv] unless vv.respond_to?(:
|
|
85
|
+
vv = [vv] unless vv.respond_to?(:to_a)
|
|
86
86
|
vv.each do |v|
|
|
87
87
|
best = v if best.nil? || yield(v, best)
|
|
88
88
|
end
|
data/lib/factbase/terms/meta.rb
CHANGED
|
@@ -24,7 +24,7 @@ module Factbase::Term::Ordering
|
|
|
24
24
|
assert_args(1)
|
|
25
25
|
vv = the_values(0, fact, maps)
|
|
26
26
|
return false if vv.nil?
|
|
27
|
-
vv = [vv] unless vv.respond_to?(:
|
|
27
|
+
vv = [vv] unless vv.respond_to?(:to_a)
|
|
28
28
|
vv.each do |v|
|
|
29
29
|
return false if @uniques.include?(v)
|
|
30
30
|
@uniques << v
|
data/lib/factbase.rb
CHANGED
|
@@ -37,7 +37,7 @@ require 'yaml'
|
|
|
37
37
|
# {
|
|
38
38
|
# 'name': ['Jeff', 'Walter'],
|
|
39
39
|
# 'age': [42, 'unknown'],
|
|
40
|
-
# 'place: 'LA'
|
|
40
|
+
# 'place': 'LA'
|
|
41
41
|
# }
|
|
42
42
|
#
|
|
43
43
|
# Value sets, as you can see, allow data of different types. However, there
|
|
@@ -64,7 +64,7 @@ require 'yaml'
|
|
|
64
64
|
# License:: MIT
|
|
65
65
|
class Factbase
|
|
66
66
|
# Current version of the gem (changed by .rultor.yml on every release)
|
|
67
|
-
VERSION = '0.7.
|
|
67
|
+
VERSION = '0.7.5'
|
|
68
68
|
|
|
69
69
|
# An exception that may be thrown in a transaction, to roll it back.
|
|
70
70
|
class Rollback < StandardError; end
|
|
@@ -150,20 +150,18 @@ class Factbase
|
|
|
150
150
|
# @return [Factbase::Churn] How many facts have been changed (zero if rolled back)
|
|
151
151
|
def txn
|
|
152
152
|
pairs = {}
|
|
153
|
-
lookup = {}
|
|
154
153
|
before =
|
|
155
154
|
@mutex.synchronize do
|
|
156
155
|
@maps.map do |m|
|
|
157
156
|
n = m.transform_values(&:dup)
|
|
158
157
|
# rubocop:disable Lint/HashCompareByIdentity
|
|
159
158
|
pairs[n.object_id] = m.object_id
|
|
160
|
-
lookup[n.object_id] = n
|
|
161
159
|
# rubocop:enable Lint/HashCompareByIdentity
|
|
162
160
|
n
|
|
163
161
|
end
|
|
164
162
|
end
|
|
165
163
|
require_relative 'factbase/taped'
|
|
166
|
-
taped = Factbase::Taped.new(before
|
|
164
|
+
taped = Factbase::Taped.new(before)
|
|
167
165
|
begin
|
|
168
166
|
require_relative 'factbase/light'
|
|
169
167
|
yield Factbase::Light.new(Factbase.new(taped, cache: @cache), @cache)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../../test__helper'
|
|
7
7
|
require_relative '../../../lib/factbase/term'
|
|
8
8
|
require_relative '../../../lib/factbase/syntax'
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ require_relative '../../../lib/factbase/syntax'
|
|
|
11
11
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
12
12
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
13
13
|
# License:: MIT
|
|
14
|
-
class TestAggregates <
|
|
14
|
+
class TestAggregates < Factbase::Test
|
|
15
15
|
def test_aggregation
|
|
16
16
|
maps = [
|
|
17
17
|
{ 'x' => [1], 'y' => [0], 'z' => [4] },
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../../test__helper'
|
|
7
7
|
require_relative '../../../lib/factbase/term'
|
|
8
8
|
require_relative '../../../lib/factbase/syntax'
|
|
9
9
|
require_relative '../../../lib/factbase/accum'
|
|
@@ -12,7 +12,7 @@ require_relative '../../../lib/factbase/accum'
|
|
|
12
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
13
13
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
14
14
|
# License:: MIT
|
|
15
|
-
class TestAliases <
|
|
15
|
+
class TestAliases < Factbase::Test
|
|
16
16
|
def test_aliases
|
|
17
17
|
maps = [
|
|
18
18
|
{ 'x' => [1], 'y' => [0], 't1' => [Time.now], 't2' => [Time.now] },
|
|
@@ -47,8 +47,8 @@ class TestAliases < Minitest::Test
|
|
|
47
47
|
t = Factbase::Syntax.new(Factbase.new, q).to_term
|
|
48
48
|
maps.each do |m|
|
|
49
49
|
f = Factbase::Accum.new(fact(m), {}, false)
|
|
50
|
-
require_relative '../../../lib/factbase/
|
|
51
|
-
f = Factbase::
|
|
50
|
+
require_relative '../../../lib/factbase/logged'
|
|
51
|
+
f = Factbase::Logged::Fact.new(f, Loog::NULL)
|
|
52
52
|
next unless t.evaluate(f, maps)
|
|
53
53
|
assert(Factbase::Syntax.new(Factbase.new, r).to_term.evaluate(f, []), "#{q} -> #{f} doesn't match #{r}")
|
|
54
54
|
end
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
require 'minitest/autorun'
|
|
7
6
|
require_relative '../../test__helper'
|
|
8
7
|
require_relative '../../../lib/factbase/term'
|
|
9
8
|
|
|
@@ -11,7 +10,7 @@ require_relative '../../../lib/factbase/term'
|
|
|
11
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
12
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
13
12
|
# License:: MIT
|
|
14
|
-
class TestCasting <
|
|
13
|
+
class TestCasting < Factbase::Test
|
|
15
14
|
def test_to_str
|
|
16
15
|
t = Factbase::Term.new(Factbase.new, :to_string, [Time.now])
|
|
17
16
|
assert_equal('String', t.evaluate(fact, []).class.to_s)
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../../test__helper'
|
|
7
7
|
require_relative '../../../lib/factbase/term'
|
|
8
8
|
|
|
9
9
|
# Debug test.
|
|
10
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
11
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
12
12
|
# License:: MIT
|
|
13
|
-
class TestDebug <
|
|
13
|
+
class TestDebug < Factbase::Test
|
|
14
14
|
def test_traced
|
|
15
15
|
t = Factbase::Term.new(Factbase.new, :traced, [Factbase::Term.new(Factbase.new, :defn, [:test_debug, 'self.to_s'])])
|
|
16
16
|
assert_output("(traced (defn test_debug 'self.to_s')) -> true\n") do
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../../test__helper'
|
|
7
7
|
require_relative '../../../lib/factbase/term'
|
|
8
8
|
|
|
9
9
|
# Defn test.
|
|
10
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
11
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
12
12
|
# License:: MIT
|
|
13
|
-
class TestDefn <
|
|
13
|
+
class TestDefn < Factbase::Test
|
|
14
14
|
def test_defn_simple
|
|
15
15
|
t = Factbase::Term.new(Factbase.new, :defn, [:foo, 'self.to_s'])
|
|
16
16
|
assert(t.evaluate(fact('foo' => 4), []))
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../../test__helper'
|
|
7
7
|
require_relative '../../../lib/factbase/term'
|
|
8
8
|
|
|
9
9
|
# Logical test.
|
|
10
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
11
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
12
12
|
# License:: MIT
|
|
13
|
-
class TestLogical <
|
|
13
|
+
class TestLogical < Factbase::Test
|
|
14
14
|
def test_not_matching
|
|
15
15
|
t = Factbase::Term.new(Factbase.new, :not, [Factbase::Term.new(Factbase.new, :always, [])])
|
|
16
16
|
refute(t.evaluate(fact('foo' => [100]), []))
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
require 'minitest/autorun'
|
|
7
6
|
require_relative '../../test__helper'
|
|
8
7
|
require_relative '../../../lib/factbase/term'
|
|
9
8
|
|
|
@@ -11,7 +10,7 @@ require_relative '../../../lib/factbase/term'
|
|
|
11
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
12
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
13
12
|
# License:: MIT
|
|
14
|
-
class TestMath <
|
|
13
|
+
class TestMath < Factbase::Test
|
|
15
14
|
def test_simple
|
|
16
15
|
t = Factbase::Term.new(Factbase.new, :eq, [:foo, 42])
|
|
17
16
|
assert(t.evaluate(fact('foo' => [42]), []))
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../../test__helper'
|
|
7
7
|
require_relative '../../../lib/factbase/term'
|
|
8
8
|
|
|
9
9
|
# Meta test.
|
|
10
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
11
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
12
12
|
# License:: MIT
|
|
13
|
-
class TestMeta <
|
|
13
|
+
class TestMeta < Factbase::Test
|
|
14
14
|
def test_exists
|
|
15
15
|
t = Factbase::Term.new(Factbase.new, :exists, [:foo])
|
|
16
16
|
assert(t.evaluate(fact('foo' => 41), []))
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../../test__helper'
|
|
7
7
|
require_relative '../../../lib/factbase/term'
|
|
8
8
|
|
|
9
9
|
# Ordering test.
|
|
10
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
11
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
12
12
|
# License:: MIT
|
|
13
|
-
class TestOrdering <
|
|
13
|
+
class TestOrdering < Factbase::Test
|
|
14
14
|
def test_prev
|
|
15
15
|
t = Factbase::Term.new(Factbase.new, :prev, [:foo])
|
|
16
16
|
assert_nil(t.evaluate(fact('foo' => 41), []))
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../../test__helper'
|
|
7
7
|
require_relative '../../../lib/factbase/term'
|
|
8
8
|
|
|
9
9
|
# Strings test.
|
|
10
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
11
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
12
12
|
# License:: MIT
|
|
13
|
-
class TestStrings <
|
|
13
|
+
class TestStrings < Factbase::Test
|
|
14
14
|
def test_regexp_matching
|
|
15
15
|
t = Factbase::Term.new(Factbase.new, :matches, [:foo, '[a-z]+'])
|
|
16
16
|
assert(t.evaluate(fact('foo' => 'hello'), []))
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
require 'minitest/autorun'
|
|
7
6
|
require_relative '../../test__helper'
|
|
8
7
|
require_relative '../../../lib/factbase/term'
|
|
9
8
|
|
|
@@ -11,7 +10,7 @@ require_relative '../../../lib/factbase/term'
|
|
|
11
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
12
11
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
13
12
|
# License:: MIT
|
|
14
|
-
class TestSystem <
|
|
13
|
+
class TestSystem < Factbase::Test
|
|
15
14
|
def test_env
|
|
16
15
|
ENV.store('FOO', 'bar')
|
|
17
16
|
t = Factbase::Term.new(Factbase.new, :env, ['FOO', ''])
|
data/test/factbase/test_accum.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../test__helper'
|
|
7
7
|
require_relative '../../lib/factbase'
|
|
8
8
|
require_relative '../../lib/factbase/accum'
|
|
9
9
|
require_relative '../../lib/factbase/fact'
|
|
@@ -12,7 +12,7 @@ require_relative '../../lib/factbase/fact'
|
|
|
12
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
13
13
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
14
14
|
# License:: MIT
|
|
15
|
-
class TestAccum <
|
|
15
|
+
class TestAccum < Factbase::Test
|
|
16
16
|
def test_holds_props
|
|
17
17
|
map = {}
|
|
18
18
|
f = Factbase::Fact.new(Factbase.new, Mutex.new, map)
|
data/test/factbase/test_churn.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../test__helper'
|
|
7
7
|
require 'loog'
|
|
8
8
|
require_relative '../../lib/factbase'
|
|
9
9
|
require_relative '../../lib/factbase/churn'
|
|
@@ -12,7 +12,7 @@ require_relative '../../lib/factbase/churn'
|
|
|
12
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
13
13
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
14
14
|
# License:: MIT
|
|
15
|
-
class TestChurn <
|
|
15
|
+
class TestChurn < Factbase::Test
|
|
16
16
|
def test_appends
|
|
17
17
|
c = Factbase::Churn.new
|
|
18
18
|
c.append(1, 2, 3)
|
data/test/factbase/test_fact.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../test__helper'
|
|
7
7
|
require_relative '../../lib/factbase'
|
|
8
8
|
require_relative '../../lib/factbase/fact'
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ require_relative '../../lib/factbase/fact'
|
|
|
11
11
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
12
12
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
13
13
|
# License:: MIT
|
|
14
|
-
class TestFact <
|
|
14
|
+
class TestFact < Factbase::Test
|
|
15
15
|
def test_injects_data_correctly
|
|
16
16
|
map = {}
|
|
17
17
|
f = Factbase::Fact.new(Factbase.new, Mutex.new, map)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../test__helper'
|
|
7
7
|
require_relative '../../lib/factbase'
|
|
8
8
|
require_relative '../../lib/factbase/flatten'
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ require_relative '../../lib/factbase/flatten'
|
|
|
11
11
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
12
12
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
13
13
|
# License:: MIT
|
|
14
|
-
class TestFlatten <
|
|
14
|
+
class TestFlatten < Factbase::Test
|
|
15
15
|
def test_mapping
|
|
16
16
|
maps = [{ 'b' => [42], 'i' => 1 }, { 'a' => 33, 'i' => 0 }, { 'c' => %w[hey you], 'i' => 2 }]
|
|
17
17
|
to = Factbase::Flatten.new(maps, 'i').it
|
data/test/factbase/test_inv.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../test__helper'
|
|
7
7
|
require 'loog'
|
|
8
8
|
require_relative '../../lib/factbase'
|
|
9
9
|
require_relative '../../lib/factbase/inv'
|
|
@@ -13,7 +13,7 @@ require_relative '../../lib/factbase/pre'
|
|
|
13
13
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
14
14
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
15
15
|
# License:: MIT
|
|
16
|
-
class TestInv <
|
|
16
|
+
class TestInv < Factbase::Test
|
|
17
17
|
def test_simple_checking
|
|
18
18
|
fb =
|
|
19
19
|
Factbase::Inv.new(Factbase.new) do |p, v|
|
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../test__helper'
|
|
7
7
|
require 'loog'
|
|
8
8
|
require_relative '../../lib/factbase'
|
|
9
|
-
require_relative '../../lib/factbase/
|
|
9
|
+
require_relative '../../lib/factbase/logged'
|
|
10
10
|
|
|
11
11
|
# Test.
|
|
12
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
13
13
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
14
14
|
# License:: MIT
|
|
15
|
-
class
|
|
15
|
+
class TestLogged < Factbase::Test
|
|
16
16
|
def test_simple_setting
|
|
17
|
-
fb = Factbase::
|
|
17
|
+
fb = Factbase::Logged.new(Factbase.new, Loog::NULL)
|
|
18
18
|
fb.insert
|
|
19
19
|
fb.insert.bar = 3
|
|
20
20
|
found = 0
|
|
@@ -29,7 +29,7 @@ class TestLooged < Minitest::Test
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def test_reading_one
|
|
32
|
-
fb = Factbase::
|
|
32
|
+
fb = Factbase::Logged.new(Factbase.new, Loog::NULL)
|
|
33
33
|
fb.insert
|
|
34
34
|
fb.insert.bar = 42
|
|
35
35
|
assert_equal(1, fb.query('(agg (exists bar) (count))').one)
|
|
@@ -38,7 +38,7 @@ class TestLooged < Minitest::Test
|
|
|
38
38
|
|
|
39
39
|
def test_with_txn
|
|
40
40
|
log = Loog::Buffer.new
|
|
41
|
-
fb = Factbase::
|
|
41
|
+
fb = Factbase::Logged.new(Factbase.new, log)
|
|
42
42
|
assert(
|
|
43
43
|
fb.txn do |fbt|
|
|
44
44
|
fbt.insert.foo = 42
|
|
@@ -50,7 +50,7 @@ class TestLooged < Minitest::Test
|
|
|
50
50
|
|
|
51
51
|
def test_with_txn_rollback
|
|
52
52
|
log = Loog::Buffer.new
|
|
53
|
-
fb = Factbase::
|
|
53
|
+
fb = Factbase::Logged.new(Factbase.new, log)
|
|
54
54
|
assert_equal(0, fb.txn { raise Factbase::Rollback })
|
|
55
55
|
assert_equal(0, fb.size)
|
|
56
56
|
assert_includes(log.to_s, 'rolled back', log)
|
|
@@ -59,7 +59,7 @@ class TestLooged < Minitest::Test
|
|
|
59
59
|
|
|
60
60
|
def test_with_modifying_txn
|
|
61
61
|
log = Loog::Buffer.new
|
|
62
|
-
fb = Factbase::
|
|
62
|
+
fb = Factbase::Logged.new(Factbase.new, log)
|
|
63
63
|
fb.insert.foo = 1
|
|
64
64
|
assert_equal(0, fb.txn { |fbt| fbt.query('(always)').each.to_a }.to_i, log)
|
|
65
65
|
assert_equal(1, fb.txn { |fbt| fbt.query('(always)').each.to_a[0].foo = 42 }.to_i)
|
|
@@ -68,7 +68,7 @@ class TestLooged < Minitest::Test
|
|
|
68
68
|
|
|
69
69
|
def test_with_empty_txn
|
|
70
70
|
log = Loog::Buffer.new
|
|
71
|
-
fb = Factbase::
|
|
71
|
+
fb = Factbase::Logged.new(Factbase.new, log)
|
|
72
72
|
assert_equal(0, fb.txn { |fbt| fbt.query('(always)').each.to_a }.to_i)
|
|
73
73
|
assert_includes(log.to_s, 'touched', log)
|
|
74
74
|
end
|
|
@@ -77,16 +77,16 @@ class TestLooged < Minitest::Test
|
|
|
77
77
|
fb = Factbase.new
|
|
78
78
|
fb.insert
|
|
79
79
|
fb.insert
|
|
80
|
-
assert_equal(2, Factbase::
|
|
80
|
+
assert_equal(2, Factbase::Logged.new(fb, Loog::NULL).query('(always)').each(&:to_s))
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
def test_returns_int_when_empty
|
|
84
84
|
fb = Factbase.new
|
|
85
|
-
assert_equal(0, Factbase::
|
|
85
|
+
assert_equal(0, Factbase::Logged.new(fb, Loog::NULL).query('(always)').each(&:to_s))
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
def test_logs_when_enumerator
|
|
89
|
-
fb = Factbase::
|
|
89
|
+
fb = Factbase::Logged.new(Factbase.new, Loog::NULL)
|
|
90
90
|
assert_equal(0, fb.query('(always)').each.to_a.size)
|
|
91
91
|
fb.insert
|
|
92
92
|
assert_equal(1, fb.query('(always)').each.to_a.size)
|
|
@@ -94,7 +94,7 @@ class TestLooged < Minitest::Test
|
|
|
94
94
|
|
|
95
95
|
def test_proper_logging
|
|
96
96
|
log = Loog::Buffer.new
|
|
97
|
-
fb = Factbase::
|
|
97
|
+
fb = Factbase::Logged.new(Factbase.new, log)
|
|
98
98
|
fb.insert
|
|
99
99
|
fb.insert.bar = 3
|
|
100
100
|
fb.insert
|
data/test/factbase/test_pre.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../test__helper'
|
|
7
7
|
require 'loog'
|
|
8
8
|
require_relative '../../lib/factbase/pre'
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ require_relative '../../lib/factbase/pre'
|
|
|
11
11
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
12
12
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
13
13
|
# License:: MIT
|
|
14
|
-
class TestPre <
|
|
14
|
+
class TestPre < Factbase::Test
|
|
15
15
|
def test_simple_setting
|
|
16
16
|
fb = Factbase::Pre.new(Factbase.new) { |f| f.foo = 42 }
|
|
17
17
|
f = fb.insert
|
data/test/factbase/test_query.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../test__helper'
|
|
7
7
|
require 'time'
|
|
8
8
|
require_relative '../../lib/factbase'
|
|
9
9
|
require_relative '../../lib/factbase/query'
|
|
@@ -12,7 +12,7 @@ require_relative '../../lib/factbase/query'
|
|
|
12
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
13
13
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
14
14
|
# License:: MIT
|
|
15
|
-
class TestQuery <
|
|
15
|
+
class TestQuery < Factbase::Test
|
|
16
16
|
def test_simple_parsing
|
|
17
17
|
maps = []
|
|
18
18
|
maps << { 'foo' => [42] }
|
data/test/factbase/test_rules.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
require_relative '../test__helper'
|
|
7
7
|
require_relative '../../lib/factbase'
|
|
8
8
|
require_relative '../../lib/factbase/rules'
|
|
9
9
|
require_relative '../../lib/factbase/pre'
|
|
@@ -12,7 +12,7 @@ require_relative '../../lib/factbase/pre'
|
|
|
12
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
13
13
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
|
14
14
|
# License:: MIT
|
|
15
|
-
class TestRules <
|
|
15
|
+
class TestRules < Factbase::Test
|
|
16
16
|
def test_simple_checking
|
|
17
17
|
fb = Factbase::Rules.new(
|
|
18
18
|
Factbase.new,
|