predicate 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/predicate/nodes/and.rb +7 -2
- data/lib/predicate/nodes/contradiction.rb +0 -4
- data/lib/predicate/nodes/expr.rb +1 -0
- data/lib/predicate/nodes/native.rb +6 -0
- data/lib/predicate/version.rb +1 -1
- data/lib/predicate.rb +3 -0
- data/spec/nodes/and/test_and_split.rb +18 -0
- data/spec/nodes/or/test_and_split.rb +26 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 301830894045bb25bd0641f77273a4924e8ff743
|
4
|
+
data.tar.gz: b04f894cb93548246b50085170cc83e3d1476acc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e1968b96700a0cb15da2d143fa3d0776d26ee54855232dc0e30e2854748ffd5b12c3767cb8121d95aa006d6c6a6695bf091ea262d4a8de5e1c5c099e73d730c
|
7
|
+
data.tar.gz: 3f0c0192c97d90654b36de5dbaf4a94c18a86a1787a13d27ec9d127902b8c48cd5969bca338695024b33dbd62f8dcfcfc1513cb44bcc9adcfbd2d39ef74bd1a0
|
data/lib/predicate/nodes/and.rb
CHANGED
@@ -7,9 +7,14 @@ class Predicate
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def and_split(attr_list)
|
10
|
+
# Say we are X = X1 & X2 & X3
|
11
|
+
# We will split each term: X = (X1 & Y1) & (X2 & Y2) & (X3 & Y3)
|
12
|
+
# ... such that Y1, Y2, and Y2 makes no reference to attr_list
|
13
|
+
# ... which is equivalent to (X1 & X2 & X3) & (Y1 & Y2 & Y3)
|
14
|
+
# ... hence P1 & P2, that we return
|
10
15
|
sexpr_body.inject([tautology, tautology]) do |(top,down),term|
|
11
|
-
|
12
|
-
[top &
|
16
|
+
p1, p2 = term.and_split(attr_list)
|
17
|
+
[top & p1, down & p2]
|
13
18
|
end
|
14
19
|
end
|
15
20
|
|
data/lib/predicate/nodes/expr.rb
CHANGED
@@ -10,6 +10,12 @@ class Predicate
|
|
10
10
|
self[1]
|
11
11
|
end
|
12
12
|
|
13
|
+
def and_split(attr_list)
|
14
|
+
# I possibly make references to those attributes, so
|
15
|
+
# I can't be P2
|
16
|
+
[ self, tautology ]
|
17
|
+
end
|
18
|
+
|
13
19
|
def to_ruby_code(scope = 't')
|
14
20
|
if proc.respond_to?(:source_code)
|
15
21
|
code = proc.source_code
|
data/lib/predicate/version.rb
CHANGED
data/lib/predicate.rb
CHANGED
@@ -88,6 +88,9 @@ class Predicate
|
|
88
88
|
to_proc.call(tuple)
|
89
89
|
end
|
90
90
|
|
91
|
+
# Splits this predicate, say P, as too predicates P1 & P2
|
92
|
+
# such that `P <=> P1 & P2` and P2 makes no reference to
|
93
|
+
# any attribute in `attr_list`.
|
91
94
|
def and_split(attr_list)
|
92
95
|
expr.and_split(attr_list).map{|e| Predicate.new(e)}
|
93
96
|
end
|
@@ -62,5 +62,23 @@ class Predicate
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
context 'with a native on one side' do
|
66
|
+
let(:left) { Factory.eq(:x, 2) }
|
67
|
+
let(:right){ Factory.native(->(t){}) }
|
68
|
+
let(:predicate){ left & right }
|
69
|
+
|
70
|
+
context 'when fully covered' do
|
71
|
+
let(:list){ [:x, :y, :z] }
|
72
|
+
|
73
|
+
it{ should eq([predicate, tautology]) }
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when not covered' do
|
77
|
+
let(:list){ [:y] }
|
78
|
+
|
79
|
+
it{ should eq([right, left]) }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
65
83
|
end
|
66
84
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
class Predicate
|
3
|
+
describe Or, "and_split" do
|
4
|
+
|
5
|
+
let(:tautology){ Factory.tautology }
|
6
|
+
|
7
|
+
subject{ predicate.and_split(list) }
|
8
|
+
|
9
|
+
context 'when attributes on one side' do
|
10
|
+
let(:predicate){ Factory.eq(:x, 2) | Factory.eq(:y, 3) }
|
11
|
+
|
12
|
+
context 'when fully covered' do
|
13
|
+
let(:list){ [:x, :y] }
|
14
|
+
|
15
|
+
it{ should eq([predicate, tautology]) }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when fully disjoint' do
|
19
|
+
let(:list){ [:z] }
|
20
|
+
|
21
|
+
it{ should eq([tautology, predicate]) }
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: predicate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- spec/nodes/identifier/test_free_variables.rb
|
153
153
|
- spec/nodes/identifier/test_name.rb
|
154
154
|
- spec/nodes/nadic_bool/test_free_variables.rb
|
155
|
+
- spec/nodes/or/test_and_split.rb
|
155
156
|
- spec/nodes/qualified_identifier/test_and_split.rb
|
156
157
|
- spec/nodes/qualified_identifier/test_free_variables.rb
|
157
158
|
- spec/nodes/qualified_identifier/test_name.rb
|