wongi-engine 0.4.0 → 0.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6436f3939185ba3c379a4fb06a9df42f9eda8e2b70fc3ba15dee97ba868dbd59
4
- data.tar.gz: 209e4bfc4814cc52950f84e9d95ceb9a1c0298ca04801e350856467df95d0c7f
3
+ metadata.gz: 461346062a679921c61fc0b35bc2e89ef0d06920745d650b48fedbbc452b780a
4
+ data.tar.gz: df2bf13a3551dc049e08398b11ac42440a34e4cb651f5092b74d3efdd5a3aecf
5
5
  SHA512:
6
- metadata.gz: 045d9b46743c8a36c9398764864d5c333939500018f853289724e34b4564794c816704e37bc1cf74d7096b57ea56d91ced165ea4a57ac5105bc9efe1797dd7ee
7
- data.tar.gz: bcb075bd1367b1c146a3299ebad4409defe227b8f4bd1d8d4c2aeefe7d5d8765602642edb1105b9abd8379595d2431412de95b3a1fd142c87bffe90e094df50b
6
+ metadata.gz: 0a3495df610621e35c8cef1a0cbf39aa0b26a8cee6d699df2bf4cdb451f4c06db534d7943bb4f30778d21289406d54ba0264f54ecfe3b839e3b1d50ccd6b63b3
7
+ data.tar.gz: 8f85d69a8f476eec9a6ee8cf97ade3a4b8e9959616114511ca65007cd225feb0963613750628a450d5ea5f905fcaed65082662db828491a7caa9c533dc70db37
@@ -86,6 +86,12 @@ module Wongi::Engine::DSL
86
86
  clause :gte
87
87
  accept Wongi::Engine::GreaterThanOrEqualTest
88
88
 
89
+ clause :in_list
90
+ accept Wongi::Engine::InListTest
91
+
92
+ clause :not_in_list
93
+ accept Wongi::Engine::NotInListTest
94
+
89
95
  clause :aggregate
90
96
  accept Clause::Aggregate
91
97
 
@@ -27,7 +27,7 @@ module Wongi::Engine
27
27
  end
28
28
 
29
29
  def ==(other)
30
- super && x == other.x && y == other.y
30
+ self.class == other.class && x == other.x && y == other.y
31
31
  end
32
32
  end
33
33
  end
@@ -29,7 +29,7 @@ module Wongi::Engine
29
29
  end
30
30
 
31
31
  def ==(other)
32
- super && x == other.x && y == other.y
32
+ self.class == other.class && x == other.x && y == other.y
33
33
  end
34
34
  end
35
35
  end
@@ -27,7 +27,7 @@ module Wongi::Engine
27
27
  end
28
28
 
29
29
  def ==(other)
30
- super && x == other.x && y == other.y
30
+ self.class == other.class && x == other.x && y == other.y
31
31
  end
32
32
  end
33
33
  end
@@ -0,0 +1,33 @@
1
+ module Wongi::Engine
2
+ class InListTest < FilterTest
3
+ attr_reader :x, :y
4
+
5
+ def initialize(x, y)
6
+ super()
7
+ @x = x
8
+ @y = y
9
+ end
10
+
11
+ def passes?(token)
12
+ x = if Template.variable? @x
13
+ token[@x]
14
+ else
15
+ @x
16
+ end
17
+
18
+ y = if Template.variable? @y
19
+ token[@y]
20
+ else
21
+ @y
22
+ end
23
+
24
+ return false if x == :_ || y == :_
25
+
26
+ y.include?(x)
27
+ end
28
+
29
+ def ==(other)
30
+ self.class == other.class && x == other.x && y == other.y
31
+ end
32
+ end
33
+ end
@@ -27,7 +27,7 @@ module Wongi::Engine
27
27
  end
28
28
 
29
29
  def ==(other)
30
- super && x == other.x && y == other.y
30
+ self.class == other.class && x == other.x && y == other.y
31
31
  end
32
32
  end
33
33
  end
@@ -29,7 +29,7 @@ module Wongi::Engine
29
29
  end
30
30
 
31
31
  def ==(other)
32
- super && x == other.x && y == other.y
32
+ self.class == other.class && x == other.x && y == other.y
33
33
  end
34
34
  end
35
35
  end
@@ -27,7 +27,7 @@ module Wongi::Engine
27
27
  end
28
28
 
29
29
  def ==(other)
30
- super && x == other.x && y == other.y
30
+ self.class == other.class && x == other.x && y == other.y
31
31
  end
32
32
  end
33
33
  end
@@ -0,0 +1,33 @@
1
+ module Wongi::Engine
2
+ class NotInListTest < FilterTest
3
+ attr_reader :x, :y
4
+
5
+ def initialize(x, y)
6
+ super()
7
+ @x = x
8
+ @y = y
9
+ end
10
+
11
+ def passes?(token)
12
+ x = if Template.variable? @x
13
+ token[@x]
14
+ else
15
+ @x
16
+ end
17
+
18
+ y = if Template.variable? @y
19
+ token[@y]
20
+ else
21
+ @y
22
+ end
23
+
24
+ return false if x == :_ || y == :_
25
+
26
+ !y.include?(x)
27
+ end
28
+
29
+ def ==(other)
30
+ self.class == other.class && x == other.x && y == other.y
31
+ end
32
+ end
33
+ end
@@ -6,3 +6,5 @@ require 'wongi-engine/filter/less_than_test'
6
6
  require 'wongi-engine/filter/greater_than_test'
7
7
  require 'wongi-engine/filter/less_than_or_equal_test'
8
8
  require 'wongi-engine/filter/greater_than_or_equal_test'
9
+ require 'wongi-engine/filter/in_list_test'
10
+ require 'wongi-engine/filter/not_in_list_test'
@@ -1,5 +1,5 @@
1
1
  module Wongi
2
2
  module Engine
3
- VERSION = "0.4.0".freeze
3
+ VERSION = "0.4.2".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wongi::Engine::InListTest do
4
+ include Wongi::Engine::DSL
5
+ let(:engine) { Wongi::Engine.create }
6
+
7
+ it "passes when the value is in the literal list" do
8
+ prod = engine << rule {
9
+ forall {
10
+ has :X, :is, :value
11
+ in_list :X, [1, 2, 3]
12
+ }
13
+ }
14
+
15
+ engine << [1, :is, :value]
16
+ expect(prod.size).to eq(1)
17
+ end
18
+
19
+ it "does not when the value is not in the literal list" do
20
+ prod = engine << rule {
21
+ forall {
22
+ has :X, :is, :value
23
+ in_list :X, [1, 2, 3]
24
+ }
25
+ }
26
+
27
+ engine << [0, :is, :value]
28
+ expect(prod.size).to eq(0)
29
+ end
30
+
31
+ it "passes when the value is in the variable list" do
32
+ prod = engine << rule {
33
+ forall {
34
+ has :X, :is, :value
35
+ has :Y, :is, :list
36
+ in_list :X, :Y
37
+ }
38
+ }
39
+
40
+ engine << [1, :is, :value]
41
+ engine << [[1, 2, 3], :is, :list]
42
+ expect(prod.size).to eq(1)
43
+ end
44
+
45
+ it "does not when the value is not in the variable list" do
46
+ prod = engine << rule {
47
+ forall {
48
+ has :X, :is, :value
49
+ has :Y, :is, :list
50
+ in_list :X, :Y
51
+ }
52
+ }
53
+
54
+ engine << [0, :is, :value]
55
+ engine << [[1, 2, 3], :is, :list]
56
+ expect(prod.size).to eq(0)
57
+ end
58
+ end
59
+
60
+ describe Wongi::Engine::NotInListTest do
61
+ include Wongi::Engine::DSL
62
+ let(:engine) { Wongi::Engine.create }
63
+
64
+ it "passes when the value is not in the literal list" do
65
+ prod = engine << rule {
66
+ forall {
67
+ has :X, :is, :value
68
+ not_in_list :X, [1, 2, 3]
69
+ }
70
+ }
71
+
72
+ engine << [0, :is, :value]
73
+ expect(prod.size).to eq(1)
74
+ end
75
+
76
+ it "does not when the value is in the literal list" do
77
+ prod = engine << rule {
78
+ forall {
79
+ has :X, :is, :value
80
+ not_in_list :X, [1, 2, 3]
81
+ }
82
+ }
83
+
84
+ engine << [1, :is, :value]
85
+ expect(prod.size).to eq(0)
86
+ end
87
+
88
+ it "passes when the value is not in the variable list" do
89
+ prod = engine << rule {
90
+ forall {
91
+ has :X, :is, :value
92
+ has :Y, :is, :list
93
+ not_in_list :X, :Y
94
+ }
95
+ }
96
+
97
+ engine << [0, :is, :value]
98
+ engine << [[1, 2, 3], :is, :list]
99
+ expect(prod.size).to eq(1)
100
+ end
101
+
102
+ it "does not when the value is in the variable list" do
103
+ prod = engine << rule {
104
+ forall {
105
+ has :X, :is, :value
106
+ has :Y, :is, :list
107
+ not_in_list :X, :Y
108
+ }
109
+ }
110
+
111
+ engine << [1, :is, :value]
112
+ engine << [[1, 2, 3], :is, :list]
113
+ expect(prod.size).to eq(0)
114
+ end
115
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wongi-engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valeri Sokolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-09 00:00:00.000000000 Z
11
+ date: 2022-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -137,9 +137,11 @@ files:
137
137
  - lib/wongi-engine/filter/filter_test.rb
138
138
  - lib/wongi-engine/filter/greater_than_or_equal_test.rb
139
139
  - lib/wongi-engine/filter/greater_than_test.rb
140
+ - lib/wongi-engine/filter/in_list_test.rb
140
141
  - lib/wongi-engine/filter/inequality_test.rb
141
142
  - lib/wongi-engine/filter/less_than_or_equal_test.rb
142
143
  - lib/wongi-engine/filter/less_than_test.rb
144
+ - lib/wongi-engine/filter/not_in_list_test.rb
143
145
  - lib/wongi-engine/generator_tracker.rb
144
146
  - lib/wongi-engine/graph.rb
145
147
  - lib/wongi-engine/join_results.rb
@@ -168,6 +170,7 @@ files:
168
170
  - spec/generation_spec.rb
169
171
  - spec/greater_than_equality_test_spec.rb
170
172
  - spec/high_level_spec.rb
173
+ - spec/in_list_spec.rb
171
174
  - spec/less_test_spec.rb
172
175
  - spec/less_than_equality_test_spec.rb
173
176
  - spec/maybe_rule_spec.rb