-
Notifications
You must be signed in to change notification settings - Fork 0
/
inference_spec.rb
90 lines (73 loc) · 2.18 KB
/
inference_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require 'spec_helper'
describe 'inference' do
it 'works' do
Environment.new do |e|
e.assert(:test)
e.rule(:test) do |r|
r.conditions :test
r.activations do
e.assert(:activated)
end
end
expect(e.facts).not_to include :activated
e.step
expect(e.facts).to include :activated
end
end
it 'assigns variables' do
Environment.new do |e|
e.assert [:in, :box, :hall]
e.rule(:move) do |r|
r.conditions [:in, :@object, :hall]
r.activations do
e.retract [:in, @object, :hall]
e.assert [:in, @object, :garage]
end
end
expect(e.facts).to include [:in,:box,:hall]
expect(e.facts).not_to include [:in,:box,:garage]
e.step
expect(e.facts).not_to include [:in,:box,:hall]
expect(e.facts).to include [:in,:box,:garage]
end
end
context 'multiple conditions' do
it 'and works' do
Environment.new do |e|
e.assert [:in, :box, :hall],[:in, :robot, :hall]
e.rule(:move) do |r|
r.conditions [:in,:@object,:@loc],[:in,:robot,:@loc]
r.activations do
e.retract [:in, @object, @loc]
e.assert [:in, @object, :garage]
e.retract [:in, :robot, @loc]
e.assert [:in, :robot, :garage]
end
end
e.step
expect(e.facts).not_to include [:in,:box,:hall]
expect(e.facts).to include [:in,:box,:garage]
expect(e.facts).not_to include [:in,:robot,:hall]
expect(e.facts).to include [:in,:robot,:garage]
end
end
it 'and + or works' do
Environment.new do |e|
e.assert [:in, :box, :hall],[:in, :robot1, :garage],[:in, :robot2, :hall]
e.rule(:move) do |r|
r.conditions do |c|
c.and([:in,:box,:@loc],
c.or([:in,:robot1,:@loc],[:in,:robot2,:@loc]))
end
r.activations do
e.retract [:in, :box, @loc]
e.assert [:in, :box, :garage]
end
end
e.step
expect(e.facts).not_to include [:in,:box,:hall]
expect(e.facts).to include [:in,:box,:garage]
end
end
end
end