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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2faa507af72faac3d76ea9e9a5f1b4fade753afa
4
- data.tar.gz: dcb6ca71f2d7d35acf950877428c31e6755944e3
3
+ metadata.gz: 301830894045bb25bd0641f77273a4924e8ff743
4
+ data.tar.gz: b04f894cb93548246b50085170cc83e3d1476acc
5
5
  SHA512:
6
- metadata.gz: a3536e379bbbc676be3572761887d9d8752b073fbbe9892518fcff2a3de13818b3cb958e19cad86402db7b0c5566e286dfac1126543c6b8a96173b36463691ba
7
- data.tar.gz: 543b030ece30b9bda05e3a61616d2aaf7c7d4b2e271665609c77e548b87a5dbb7063e1ca602f556fe119d89b9a8445fff30d79edd4564a501844b376d28c9c64
6
+ metadata.gz: 3e1968b96700a0cb15da2d143fa3d0776d26ee54855232dc0e30e2854748ffd5b12c3767cb8121d95aa006d6c6a6695bf091ea262d4a8de5e1c5c099e73d730c
7
+ data.tar.gz: 3f0c0192c97d90654b36de5dbaf4a94c18a86a1787a13d27ec9d127902b8c48cd5969bca338695024b33dbd62f8dcfcfc1513cb44bcc9adcfbd2d39ef74bd1a0
@@ -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
- pair = term.and_split(attr_list)
12
- [top & pair.first, down & pair.last]
16
+ p1, p2 = term.and_split(attr_list)
17
+ [top & p1, down & p2]
13
18
  end
14
19
  end
15
20
 
@@ -26,9 +26,5 @@ class Predicate
26
26
  @free_variables ||= []
27
27
  end
28
28
 
29
- def and_split(*args)
30
- [tautology, self]
31
- end
32
-
33
29
  end
34
30
  end
@@ -36,6 +36,7 @@ class Predicate
36
36
  end
37
37
 
38
38
  def and_split(attr_list)
39
+ # If we have no reference to attr_list, then we are P2, else we are P1
39
40
  (free_variables & attr_list).empty? ? [ tautology, self ] : [ self, tautology ]
40
41
  end
41
42
 
@@ -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
@@ -2,7 +2,7 @@ class Predicate
2
2
  module Version
3
3
  MAJOR = 1
4
4
  MINOR = 1
5
- TINY = 2
5
+ TINY = 3
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
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.2
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