wongi-engine 0.0.14 → 0.0.16

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.
@@ -34,11 +34,11 @@ describe 'the engine' do
34
34
 
35
35
  rete << Wongi::Engine::WME.new( "friend", "symmetric", true )
36
36
  rete << Wongi::Engine::WME.new( "Alice", "friend", "Bob" )
37
-
38
- rete.should have(3).facts
39
- rete.facts.select( &:manual? ).should have(2).items
37
+
38
+ expect(rete.facts.to_a.length).to eq(3)
39
+ expect(rete.facts.select( &:manual? ).length).to eq(2)
40
40
  generated = rete.facts.find( &:generated? )
41
- generated.should == Wongi::Engine::WME.new( "Bob", "friend", "Alice" )
41
+ expect( generated ).to be == Wongi::Engine::WME.new( "Bob", "friend", "Alice" )
42
42
  end
43
43
 
44
44
  it 'should generate wmes with an added rule' do
@@ -46,7 +46,7 @@ describe 'the engine' do
46
46
  rete << Wongi::Engine::WME.new( "friend", "symmetric", true )
47
47
  rete << Wongi::Engine::WME.new( "Alice", "friend", "Bob" )
48
48
 
49
- rete.should have(2).facts
49
+ expect(rete.facts.to_a.length).to eq(2)
50
50
 
51
51
  rete << rule('symmetric') {
52
52
  forall {
@@ -58,8 +58,8 @@ describe 'the engine' do
58
58
  }
59
59
  }
60
60
 
61
- rete.should have(3).facts
62
- rete.facts.select( &:manual? ).should have(2).items
61
+ expect(rete.facts.to_a.length).to eq(3)
62
+ expect(rete.facts.select( &:manual? ).size).to eq(2)
63
63
  end
64
64
 
65
65
  it 'should not get confused by recursive activations' do
@@ -78,9 +78,9 @@ describe 'the engine' do
78
78
  rete << [:p, "reflexive", true]
79
79
  rete << [:x, :p, :y]
80
80
 
81
- expect( rete ).to have(4).wmes
82
- expect( rete.select :x, :p, :x ).to have(1).items
83
- expect( rete.select :y, :p, :y ).to have(1).items
81
+ expect(rete.wmes.to_a.length).to eq(4)
82
+ expect(rete.select(:x, :p, :x).length).to eq(1)
83
+ expect(rete.select(:y, :p, :y).length).to eq(1)
84
84
 
85
85
  end
86
86
 
@@ -99,7 +99,7 @@ describe 'the engine' do
99
99
  }
100
100
 
101
101
  rete << [ 42, "same", 42 ]
102
- node.should have(1).tokens
102
+ expect(node.size).to eq(1)
103
103
 
104
104
  end
105
105
 
@@ -131,10 +131,10 @@ describe 'the engine' do
131
131
  rete << ["Bob", :age, 43]
132
132
 
133
133
  items = rete.select "Alice", :younger, "Bob"
134
- items.should have(1).items
134
+ expect(items.size).to eq(1)
135
135
 
136
136
  items = rete.select "Bob", :older, "Alice"
137
- items.should have(1).items
137
+ expect(items.size).to eq(1)
138
138
 
139
139
  end
140
140
 
@@ -153,8 +153,8 @@ describe 'the engine' do
153
153
  rete << [ "question", "is", -1 ]
154
154
 
155
155
  collection = rete.collection(:test_collector)
156
- collection.should have(1).item
157
- collection.first.should == "answer"
156
+ expect(collection.size).to eq(1)
157
+ expect(collection.first).to eq("answer")
158
158
 
159
159
  end
160
160
 
@@ -173,14 +173,14 @@ describe 'the engine' do
173
173
  rete << [ "question", "is", -1 ]
174
174
 
175
175
  collection = rete.collection(:things_that_are_42)
176
- collection.should have(1).item
177
- collection.first.should == "answer"
176
+ expect(collection.size).to eq(1)
177
+ expect(collection.first).to eq("answer")
178
178
 
179
179
  end
180
180
 
181
181
  it 'should accept several rules' do
182
182
 
183
- lambda do
183
+ expect {
184
184
 
185
185
  rete << rule('generic-collector') {
186
186
  forall {
@@ -200,7 +200,7 @@ describe 'the engine' do
200
200
  }
201
201
  }
202
202
 
203
- end.should_not raise_error
203
+ }.not_to raise_error
204
204
 
205
205
  end
206
206
 
@@ -212,11 +212,11 @@ describe 'the engine' do
212
212
  }
213
213
  })
214
214
 
215
- production.should have(1).tokens
215
+ expect(production.size).to eq(1)
216
216
 
217
217
  rete << [ "answer", "is", 42 ]
218
218
 
219
- production.should have(0).tokens
219
+ expect(production.size).to eq(0)
220
220
 
221
221
  end
222
222
 
@@ -232,8 +232,8 @@ describe 'the engine' do
232
232
  rete << ["answer", "is", 42]
233
233
 
234
234
  rete.execute "test-query", {X: "answer"}
235
- rete.results["test-query"].should have(1).tokens
236
- rete.results["test-query"].tokens.first[:Y].should == 42
235
+ expect(rete.results["test-query"].size).to eq(1)
236
+ expect(rete.results["test-query"].tokens.first[:Y]).to eq(42)
237
237
 
238
238
  end
239
239
 
@@ -247,11 +247,11 @@ describe 'the engine' do
247
247
  }
248
248
  }
249
249
 
250
- production.should have(0).tokens
250
+ expect(production.size).to eq(0)
251
251
 
252
252
  rete << [1, 2, 3]
253
253
 
254
- production.should have(0).tokens
254
+ expect(production.size).to eq(0)
255
255
 
256
256
  end
257
257
 
@@ -266,7 +266,7 @@ describe 'the engine' do
266
266
  rete << [1, 2, 3]
267
267
  rete.snapshot!
268
268
 
269
- production.should have(1).tokens
269
+ expect(production.size).to eq(1)
270
270
 
271
271
  end
272
272
 
@@ -280,10 +280,10 @@ describe 'the engine' do
280
280
  }
281
281
  make { action { count += 1} }
282
282
  end
283
- production.should have(0).tokens
283
+ expect(production.size).to eq(0)
284
284
  rete.snapshot!
285
285
  rete << [1, 2, 3]
286
- production.should have(1).tokens
286
+ expect(production.size).to eq(1)
287
287
  #puts count
288
288
  end
289
289
 
@@ -296,9 +296,9 @@ describe 'the engine' do
296
296
  make { action { count += 1} }
297
297
  end
298
298
  rete << [1, 2, 3]
299
- production.should have(1).tokens
299
+ expect(production.size).to eq(1)
300
300
  rete.snapshot!
301
- production.should have(0).tokens
301
+ expect(production.size).to eq(0)
302
302
  #puts count
303
303
  end
304
304
 
@@ -315,9 +315,9 @@ describe 'the engine' do
315
315
  make { action { count += 1} }
316
316
  end
317
317
  rete << [1, 2, 3]
318
- production.should have(0).tokens
318
+ expect(production.size).to eq(0)
319
319
  rete.snapshot!
320
- production.should have(1).tokens
320
+ expect(production.size).to eq(1)
321
321
  #puts count
322
322
  end
323
323
 
@@ -329,10 +329,10 @@ describe 'the engine' do
329
329
  }
330
330
  make { action { count += 1} }
331
331
  end
332
- production.should have(0).tokens
332
+ expect(production.size).to eq(0)
333
333
  rete.snapshot!
334
334
  rete << [1, 2, 3]
335
- production.should have(0).tokens
335
+ expect(production.size).to eq(0)
336
336
  #puts count
337
337
  end
338
338
 
@@ -30,7 +30,7 @@ describe "ANY rule" do
30
30
  engine << [1, 2, 3]
31
31
  engine << [3, 4, 5]
32
32
 
33
- production.should have(1).tokens
33
+ expect(production.size).to eq(1)
34
34
 
35
35
  end
36
36
 
@@ -64,9 +64,9 @@ describe "ANY rule" do
64
64
  engine << [1, 2, "three"]
65
65
  engine << ["three", "four", "five"]
66
66
 
67
- production.should have(2).tokens
68
- engine.collection(:threes).should include(3)
69
- engine.collection(:threes).should include("three")
67
+ expect(production.size).to eq(2)
68
+ expect( engine.collection(:threes) ).to include(3)
69
+ expect( engine.collection(:threes) ).to include("three")
70
70
 
71
71
  end
72
72
 
@@ -27,9 +27,8 @@ describe "ASSIGN rule" do
27
27
  end
28
28
  }
29
29
  }
30
-
31
- production.should have(1).tokens
32
- production.tokens.first[:X].should == 42
30
+ expect(production.size).to eq(1)
31
+ expect(production.tokens.first[:X]).to eq(42)
33
32
 
34
33
  end
35
34
 
@@ -45,7 +44,7 @@ describe "ASSIGN rule" do
45
44
  }
46
45
 
47
46
  engine << [1, 2, 5]
48
- production.tokens.first[:Y].should == 10
47
+ expect(production.tokens.first[:Y]).to eq(10)
49
48
 
50
49
  end
51
50
 
@@ -19,15 +19,15 @@ describe "MAYBE rule" do
19
19
  }
20
20
  end
21
21
 
22
- prod = engine.productions['test']
22
+ production = engine.productions['test']
23
23
 
24
24
  engine << [1, 2, 3]
25
25
  engine << [3, 4, 5]
26
26
 
27
- prod.should have(1).tokens
27
+ expect(production.size).to eq(1)
28
28
 
29
- prod.tokens.first[:X].should == 3
30
- prod.tokens.first[:Y].should == 5
29
+ expect(production.tokens.first[:X]).to eq(3)
30
+ expect(production.tokens.first[:Y]).to eq(5)
31
31
 
32
32
  end
33
33
 
@@ -40,14 +40,14 @@ describe "MAYBE rule" do
40
40
  }
41
41
  end
42
42
 
43
- prod = engine.productions['test']
43
+ production = engine.productions['test']
44
44
 
45
45
  engine << [1, 2, 3]
46
46
 
47
- prod.should have(1).tokens
47
+ expect(production.size).to eq(1)
48
48
 
49
- prod.tokens.first[:X].should == 3
50
- prod.tokens.first[:Y].should be_nil
49
+ expect(production.tokens.first[:X]).to eq(3)
50
+ expect(production.tokens.first[:Y]).to be_nil
51
51
 
52
52
  end
53
53
 
@@ -62,12 +62,12 @@ describe "MAYBE rule" do
62
62
  }
63
63
  end
64
64
 
65
- prod = engine.productions['test']
65
+ production = engine.productions['test']
66
66
 
67
- prod.should have(1).tokens
67
+ expect(production.size).to eq(1)
68
68
 
69
- prod.tokens.first[:X].should == 3
70
- prod.tokens.first[:Y].should be_nil
69
+ expect(production.tokens.first[:X]).to eq(3)
70
+ expect(production.tokens.first[:Y]).to be_nil
71
71
 
72
72
  end
73
73
 
@@ -29,15 +29,15 @@ describe "NCC rule" do
29
29
 
30
30
  engine << ["base", "is", 1]
31
31
 
32
- production.should have(1).tokens
32
+ expect(production.size).to eq(1)
33
33
 
34
34
  engine << [1, 2, 3]
35
35
 
36
- production.should have(1).tokens
36
+ expect(production.size).to eq(1)
37
37
 
38
38
  engine << [3, 4, 5]
39
39
 
40
- production.should have(0).tokens
40
+ expect(production.size).to eq(0)
41
41
 
42
42
  end
43
43
 
@@ -50,13 +50,13 @@ describe "NCC rule" do
50
50
  engine << [1, 2, 3]
51
51
  engine << [3, 4, 5]
52
52
 
53
- production.should have(0).tokens
53
+ expect(production.size).to eq(0)
54
54
 
55
55
  engine.retract [3, 4, 5]
56
- production.should have(1).tokens
56
+ expect( production ).to have(1).token
57
57
 
58
58
  engine.retract ["base", "is", 1]
59
- production.should have(0).tokens
59
+ expect(production.size).to eq(0)
60
60
 
61
61
  end
62
62
 
@@ -1,70 +1,70 @@
1
- require 'spec_helper'
2
-
3
- describe "negative rule" do
4
-
5
- before :each do
6
- @engine = Wongi::Engine.create
7
- end
8
-
9
- def engine
10
- @engine
11
- end
12
-
13
- it "should not introduce variables" do
14
-
15
- proc = lambda {
16
-
17
- engine << rule('one-option') {
18
- forall {
19
- neg :Foo, :bar, :_
20
- }
21
- make {
22
- action { |tokens|
23
- raise "This should never get executed #{tokens}"
24
- }
25
- }
26
- }
27
-
28
- }
29
-
30
- proc.should raise_error( Wongi::Engine::DefinitionError )
31
-
32
- end
33
-
34
- # it "should not create infinite feedback loops by default" do
35
-
36
- # engine << rule('feedback') {
37
- # forall {
38
- # neg :a, :b, :_
39
- # }
40
- # make {
41
- # gen :a, :b, :c
42
- # }
43
- # }
44
-
45
- # engine.should have(1).facts
46
-
47
- # end
48
-
49
- it "should create infinite feedback loops with unsafe option" do
50
-
51
- counter = 0
52
- exception = Class.new( StandardError )
53
-
54
- proc = lambda {
55
- engine << rule('feedback') {
56
- forall {
57
- neg :a, :b, :_, unsafe: true
58
- }
59
- make {
60
- action { counter += 1 ; if counter > 5 then raise exception.new end }
61
- gen :a, :b, :c
62
- }
63
- }
64
- }
65
-
66
- proc.should raise_error( exception )
67
-
68
- end
69
-
70
- end
1
+ require 'spec_helper'
2
+
3
+ describe "negative rule" do
4
+
5
+ before :each do
6
+ @engine = Wongi::Engine.create
7
+ end
8
+
9
+ def engine
10
+ @engine
11
+ end
12
+
13
+ it "should not introduce variables" do
14
+
15
+ proc = lambda {
16
+
17
+ engine << rule('one-option') {
18
+ forall {
19
+ neg :Foo, :bar, :_
20
+ }
21
+ make {
22
+ action { |tokens|
23
+ raise "This should never get executed #{tokens}"
24
+ }
25
+ }
26
+ }
27
+
28
+ }
29
+
30
+ expect( &proc ).to raise_error( Wongi::Engine::DefinitionError )
31
+
32
+ end
33
+
34
+ # it "should not create infinite feedback loops by default" do
35
+
36
+ # engine << rule('feedback') {
37
+ # forall {
38
+ # neg :a, :b, :_
39
+ # }
40
+ # make {
41
+ # gen :a, :b, :c
42
+ # }
43
+ # }
44
+
45
+ # engine.should have(1).facts
46
+
47
+ # end
48
+
49
+ it "should create infinite feedback loops with unsafe option" do
50
+
51
+ counter = 0
52
+ exception = Class.new( StandardError )
53
+
54
+ proc = lambda {
55
+ engine << rule('feedback') {
56
+ forall {
57
+ neg :a, :b, :_, unsafe: true
58
+ }
59
+ make {
60
+ action { counter += 1 ; if counter > 5 then raise exception.new end }
61
+ gen :a, :b, :c
62
+ }
63
+ }
64
+ }
65
+
66
+ expect( &proc ).to raise_error( exception )
67
+
68
+ end
69
+
70
+ end
data/spec/ruleset_spec.rb CHANGED
@@ -9,7 +9,7 @@ describe Wongi::Engine::Ruleset do
9
9
  context 'initially' do
10
10
 
11
11
  it 'should have no rules' do
12
- Wongi::Engine::Ruleset.rulesets.should be_empty
12
+ expect( Wongi::Engine::Ruleset.rulesets ).to be_empty
13
13
  end
14
14
 
15
15
  end
@@ -18,19 +18,19 @@ describe Wongi::Engine::Ruleset do
18
18
 
19
19
  it 'should not register itself when not given a name' do
20
20
  ruleset = Wongi::Engine::Ruleset.new
21
- ruleset.name.should be_nil
22
- Wongi::Engine::Ruleset.rulesets.should be_empty
21
+ expect( ruleset.name ).to be_nil
22
+ expect( Wongi::Engine::Ruleset.rulesets ).to be_empty
23
23
  end
24
24
 
25
25
  it 'should have a name' do
26
26
  ruleset = Wongi::Engine::Ruleset.new 'testing-ruleset'
27
- ruleset.name.should == 'testing-ruleset'
27
+ expect( ruleset.name ).to be == 'testing-ruleset'
28
28
  end
29
29
 
30
30
  it 'should register itself when given a name' do
31
31
  ruleset = Wongi::Engine::Ruleset.new 'testing-ruleset'
32
- Wongi::Engine::Ruleset.rulesets.should_not be_empty
33
- Wongi::Engine::Ruleset[ruleset.name].should == ruleset
32
+ expect( Wongi::Engine::Ruleset.rulesets ).not_to be_empty
33
+ expect( Wongi::Engine::Ruleset[ruleset.name] ).to be == ruleset
34
34
  end
35
35
 
36
36
  end
@@ -38,7 +38,7 @@ describe Wongi::Engine::Ruleset do
38
38
  it 'should be able to clear registered rulesets' do
39
39
  ruleset = Wongi::Engine::Ruleset.new 'testing-ruleset'
40
40
  Wongi::Engine::Ruleset.reset
41
- Wongi::Engine::Ruleset.rulesets.should be_empty
41
+ expect( Wongi::Engine::Ruleset.rulesets ).to be_empty
42
42
  end
43
43
 
44
44
  it 'should install creating rules into a rete' do
@@ -47,7 +47,7 @@ describe Wongi::Engine::Ruleset do
47
47
  ruleset = Wongi::Engine::Ruleset.new
48
48
  rule = ruleset.rule( 'test-rule' ) { }
49
49
 
50
- rete.should_receive(:<<).with(rule).once
50
+ expect( rete ).to receive(:<<).with(rule).once
51
51
  ruleset.install rete
52
52
  end
53
53
 
@@ -25,15 +25,15 @@ describe Wongi::Engine::SimpleAction do
25
25
  }
26
26
  end
27
27
 
28
- count.should == 0
28
+ expect(count).to eq(0)
29
29
 
30
30
  rete << [1, 2, 3]
31
31
 
32
- count.should == 1
32
+ expect(count).to eq(1)
33
33
 
34
34
  rete << [1, 2, 4]
35
35
 
36
- count.should == 2
36
+ expect(count).to eq(2)
37
37
 
38
38
  end
39
39
 
data/spec/spec_helper.rb CHANGED
@@ -1 +1,3 @@
1
1
  require 'wongi-engine'
2
+ require 'rspec/collection_matchers'
3
+ require 'pry'
data/spec/wme_spec.rb CHANGED
@@ -4,9 +4,9 @@ describe Wongi::Engine::WME do
4
4
 
5
5
  def capitalizing_rete
6
6
  rete = double 'rete'
7
- rete.should_receive(:import).with("a").and_return("A")
8
- rete.should_receive(:import).with("b").and_return("B")
9
- rete.should_receive(:import).with("c").and_return("C")
7
+ expect( rete ).to receive(:import).with("b").and_return("B")
8
+ expect( rete ).to receive(:import).with("a").and_return("A")
9
+ expect( rete ).to receive(:import).with("c").and_return("C")
10
10
  rete
11
11
  end
12
12
 
@@ -17,9 +17,9 @@ describe Wongi::Engine::WME do
17
17
  context 'a new WME' do
18
18
 
19
19
  it 'should initialize and expose members' do
20
- subject.subject.should == "a"
21
- subject.predicate.should == "b"
22
- subject.object.should == "c"
20
+ expect( subject.subject ).to be == "a"
21
+ expect( subject.predicate ).to be == "b"
22
+ expect( subject.object ).to be == "c"
23
23
  end
24
24
 
25
25
  it 'should use the rete to import members' do
@@ -28,19 +28,19 @@ describe Wongi::Engine::WME do
28
28
 
29
29
  wme = Wongi::Engine::WME.new "a", "b", "c", rete
30
30
 
31
- wme.subject.should == "A"
32
- wme.predicate.should == "B"
33
- wme.object.should == "C"
31
+ expect( wme.subject ).to be == "A"
32
+ expect( wme.predicate ).to be == "B"
33
+ expect( wme.object ).to be == "C"
34
34
 
35
35
  end
36
36
 
37
37
 
38
- specify {
39
- subject.should be_manual
38
+ it {
39
+ should be_manual
40
40
  }
41
41
 
42
- specify {
43
- subject.should_not be_generated
42
+ it {
43
+ should_not be_generated
44
44
  }
45
45
 
46
46
  end
@@ -51,9 +51,9 @@ describe Wongi::Engine::WME do
51
51
 
52
52
  imported = subject.import_into rete
53
53
 
54
- imported.subject.should == "A"
55
- imported.predicate.should == "B"
56
- imported.object.should == "C"
54
+ expect( imported.subject ).to be == "A"
55
+ expect( imported.predicate ).to be == "B"
56
+ expect( imported.object ).to be == "C"
57
57
 
58
58
  end
59
59
 
@@ -63,21 +63,21 @@ describe Wongi::Engine::WME do
63
63
  wme2 = Wongi::Engine::WME.new "a", "b", "c"
64
64
  wme3 = Wongi::Engine::WME.new "a", "b", "d"
65
65
 
66
- wme1.should == wme2
67
- wme1.should_not == wme3
66
+ expect( wme1 ).to be == wme2
67
+ expect( wme1 ).not_to be == wme3
68
68
 
69
69
  end
70
70
 
71
71
  it 'should not match against non-templates' do
72
- lambda { subject =~ [1, 2, 3] }.should raise_error
72
+ expect { subject =~ [1, 2, 3] }.to raise_error
73
73
  end
74
74
 
75
75
  it 'should match against templates' do
76
76
  t1 = Wongi::Engine::Template.new "a", :_, :_
77
77
  t2 = Wongi::Engine::Template.new "b", :_, :_
78
78
 
79
- subject.should =~ t1
80
- subject.should_not =~ t2
79
+ expect( subject ).to be =~ t1
80
+ expect( subject ).not_to be =~ t2
81
81
  end
82
82
 
83
83
  end
data/wongi-engine.gemspec CHANGED
@@ -5,8 +5,9 @@ Gem::Specification.new do |gem|
5
5
  gem.authors = ["Valeri Sokolov"]
6
6
  gem.email = ["ulfurinn@ulfurinn.net"]
7
7
  gem.description = %q{A rule engine.}
8
- gem.summary = %q{A rule engine.}
8
+ gem.summary = %q{A forward-chaining rule engine in pure Ruby.}
9
9
  gem.homepage = "https://github.com/ulfurinn/wongi-engine"
10
+ gem.licenses = %w(MIT)
10
11
 
11
12
  gem.files = `git ls-files`.split($\)
12
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -15,5 +16,8 @@ Gem::Specification.new do |gem|
15
16
  gem.require_paths = ["lib"]
16
17
  gem.version = Wongi::Engine::VERSION
17
18
 
18
- gem.add_development_dependency 'rspec', '~> 2.14.1', '< 3.0.0'
19
+ gem.add_development_dependency 'rake', '~> 10'
20
+ gem.add_development_dependency 'pry', '~> 0.10'
21
+ gem.add_development_dependency 'rspec', '~> 3.1', '< 3.2'
22
+ gem.add_development_dependency 'rspec-collection_matchers', '~> 1.1'
19
23
  end