porolog 1.0.2 → 1.0.3
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 +4 -4
- data/README.md +22 -13
- data/coverage/index.html +4564 -4552
- data/doc/Array.html +9 -9
- data/doc/Object.html +1 -1
- data/doc/Porolog.html +77 -67
- data/doc/Symbol.html +1 -1
- data/doc/_index.html +1 -1
- data/doc/file.README.html +22 -14
- data/doc/index.html +22 -14
- data/doc/top-level-namespace.html +1 -1
- data/lib/porolog.rb +4 -2
- data/lib/porolog/core_ext.rb +8 -8
- data/lib/porolog/goal.rb +2 -2
- data/lib/porolog/predicate/builtin.rb +34 -34
- data/lib/porolog/rule.rb +1 -1
- data/lib/porolog/variable.rb +7 -7
- data/test/porolog/arguments_test.rb +73 -73
- data/test/porolog/core_ext_test.rb +39 -39
- data/test/porolog/goal_test.rb +72 -72
- data/test/porolog/instantiation_test.rb +153 -153
- data/test/porolog/porolog_test.rb +272 -270
- data/test/porolog/predicate/builtin_test.rb +166 -166
- data/test/porolog/predicate_test.rb +85 -85
- data/test/porolog/rule_test.rb +69 -69
- data/test/porolog/scope_test.rb +89 -89
- data/test/porolog/tail_test.rb +23 -23
- data/test/porolog/value_test.rb +32 -34
- data/test/porolog/variable_test.rb +120 -120
- data/test/samples_test.rb +11 -11
- data/test/test_helper.rb +56 -61
- metadata +2 -2
data/test/porolog/scope_test.rb
CHANGED
@@ -16,14 +16,14 @@ describe 'Porolog' do
|
|
16
16
|
describe 'Scope' do
|
17
17
|
|
18
18
|
it 'should already declare the default scope' do
|
19
|
-
assert_equal 1, Scope.scopes.size
|
20
|
-
assert_equal [:default], Scope.scopes
|
19
|
+
assert_equal 1, Porolog::Scope.scopes.size
|
20
|
+
assert_equal [:default], Porolog::Scope.scopes
|
21
21
|
|
22
|
-
assert_Scope Scope[:default], :default, []
|
22
|
+
assert_Scope Porolog::Scope[:default], :default, []
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should allow predicates with the same name to coexist in different scopes' do
|
26
|
-
prime = prime1 = Predicate.new :prime, :first
|
26
|
+
prime = prime1 = Porolog::Predicate.new :prime, :first
|
27
27
|
|
28
28
|
prime.(2).fact!
|
29
29
|
prime.(3).fact!
|
@@ -31,17 +31,17 @@ describe 'Porolog' do
|
|
31
31
|
prime.(7).fact!
|
32
32
|
prime.(11).fact!
|
33
33
|
|
34
|
-
prime = prime2 = Predicate.new :prime, :second
|
34
|
+
prime = prime2 = Porolog::Predicate.new :prime, :second
|
35
35
|
|
36
36
|
prime.('pump A').fact!
|
37
37
|
prime.('pump B').fact!
|
38
38
|
prime.('pump C').fact!
|
39
39
|
prime.('pump D').fact!
|
40
40
|
|
41
|
-
assert_equal [:default,:first,:second],
|
42
|
-
assert_Scope Scope[:default], :default,
|
43
|
-
assert_Scope Scope[:first], :first,
|
44
|
-
assert_Scope Scope[:second], :second,
|
41
|
+
assert_equal [:default,:first,:second], Porolog::Scope.scopes
|
42
|
+
assert_Scope Porolog::Scope[:default], :default, []
|
43
|
+
assert_Scope Porolog::Scope[:first], :first, [prime1]
|
44
|
+
assert_Scope Porolog::Scope[:second], :second, [prime2]
|
45
45
|
|
46
46
|
assert_equal :prime, prime1.name
|
47
47
|
assert_equal :prime, prime2.name
|
@@ -67,12 +67,12 @@ describe 'Porolog' do
|
|
67
67
|
describe '.scopes' do
|
68
68
|
|
69
69
|
it 'should return the names of all registered scopes' do
|
70
|
-
Scope.new :alpha
|
71
|
-
Scope.new :bravo
|
72
|
-
Scope.new :carly
|
70
|
+
Porolog::Scope.new :alpha
|
71
|
+
Porolog::Scope.new :bravo
|
72
|
+
Porolog::Scope.new :carly
|
73
73
|
|
74
|
-
assert_equal 4, Scope.scopes.size
|
75
|
-
assert_equal [:default, :alpha, :bravo, :carly], Scope.scopes
|
74
|
+
assert_equal 4, Porolog::Scope.scopes.size
|
75
|
+
assert_equal [:default, :alpha, :bravo, :carly], Porolog::Scope.scopes
|
76
76
|
end
|
77
77
|
|
78
78
|
end
|
@@ -80,54 +80,54 @@ describe 'Porolog' do
|
|
80
80
|
describe '.reset' do
|
81
81
|
|
82
82
|
it 'should clear all scopes' do
|
83
|
-
delta = Predicate.new :delta
|
83
|
+
delta = Porolog::Predicate.new :delta
|
84
84
|
|
85
|
-
Scope.new :alpha
|
86
|
-
Scope.new :bravo
|
87
|
-
Scope.new :carly
|
85
|
+
Porolog::Scope.new :alpha
|
86
|
+
Porolog::Scope.new :bravo
|
87
|
+
Porolog::Scope.new :carly
|
88
88
|
|
89
|
-
assert_equal 4, Scope.scopes.size
|
90
|
-
assert_equal [:default, :alpha, :bravo, :carly], Scope.scopes
|
89
|
+
assert_equal 4, Porolog::Scope.scopes.size
|
90
|
+
assert_equal [:default, :alpha, :bravo, :carly], Porolog::Scope.scopes
|
91
91
|
|
92
|
-
assert_Scope Scope[:default], :default,
|
93
|
-
assert_Scope Scope[:alpha], :alpha,
|
94
|
-
assert_Scope Scope[:bravo], :bravo,
|
95
|
-
assert_Scope Scope[:carly], :carly,
|
92
|
+
assert_Scope Porolog::Scope[:default], :default, [delta]
|
93
|
+
assert_Scope Porolog::Scope[:alpha], :alpha, []
|
94
|
+
assert_Scope Porolog::Scope[:bravo], :bravo, []
|
95
|
+
assert_Scope Porolog::Scope[:carly], :carly, []
|
96
96
|
|
97
|
-
Scope.reset
|
97
|
+
Porolog::Scope.reset
|
98
98
|
|
99
|
-
assert_equal 1, Scope.scopes.size
|
100
|
-
assert_equal [:default], Scope.scopes
|
99
|
+
assert_equal 1, Porolog::Scope.scopes.size
|
100
|
+
assert_equal [:default], Porolog::Scope.scopes
|
101
101
|
|
102
|
-
assert_Scope Scope[:default], :default,
|
102
|
+
assert_Scope Porolog::Scope[:default], :default, []
|
103
103
|
|
104
|
-
assert_nil Scope[:alpha]
|
105
|
-
assert_nil Scope[:bravo]
|
106
|
-
assert_nil Scope[:carly]
|
104
|
+
assert_nil Porolog::Scope[:alpha]
|
105
|
+
assert_nil Porolog::Scope[:bravo]
|
106
|
+
assert_nil Porolog::Scope[:carly]
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'should clear all scopes and start with a default scope when reset' do
|
110
|
-
test_predicate0 = Predicate.new 'test_predicate0'
|
111
|
-
test_predicate11 = Predicate.new 'test_predicate11', :scope1
|
112
|
-
test_predicate12 = Predicate.new 'test_predicate12', :scope1
|
113
|
-
test_predicate13 = Predicate.new 'test_predicate13', :scope1
|
114
|
-
test_predicate21 = Predicate.new 'test_predicate21', :scope2
|
115
|
-
test_predicate22 = Predicate.new 'test_predicate22', :scope2
|
116
|
-
test_predicate23 = Predicate.new 'test_predicate23', :scope2
|
110
|
+
test_predicate0 = Porolog::Predicate.new 'test_predicate0'
|
111
|
+
test_predicate11 = Porolog::Predicate.new 'test_predicate11', :scope1
|
112
|
+
test_predicate12 = Porolog::Predicate.new 'test_predicate12', :scope1
|
113
|
+
test_predicate13 = Porolog::Predicate.new 'test_predicate13', :scope1
|
114
|
+
test_predicate21 = Porolog::Predicate.new 'test_predicate21', :scope2
|
115
|
+
test_predicate22 = Porolog::Predicate.new 'test_predicate22', :scope2
|
116
|
+
test_predicate23 = Porolog::Predicate.new 'test_predicate23', :scope2
|
117
117
|
|
118
|
-
assert_equal [:default, :scope1, :scope2], Scope.scopes
|
119
|
-
assert_equal [test_predicate0], Scope[:default].predicates
|
120
|
-
assert_equal [test_predicate11, test_predicate12, test_predicate13], Scope[:scope1 ].predicates
|
121
|
-
assert_equal [test_predicate21, test_predicate22, test_predicate23], Scope[:scope2 ].predicates
|
118
|
+
assert_equal [:default, :scope1, :scope2], Porolog::Scope.scopes
|
119
|
+
assert_equal [test_predicate0], Porolog::Scope[:default].predicates
|
120
|
+
assert_equal [test_predicate11, test_predicate12, test_predicate13], Porolog::Scope[:scope1 ].predicates
|
121
|
+
assert_equal [test_predicate21, test_predicate22, test_predicate23], Porolog::Scope[:scope2 ].predicates
|
122
122
|
|
123
|
-
Scope.reset
|
123
|
+
Porolog::Scope.reset
|
124
124
|
|
125
|
-
test_predicate3 = Predicate.new 'test_predicate3'
|
125
|
+
test_predicate3 = Porolog::Predicate.new 'test_predicate3'
|
126
126
|
|
127
|
-
assert_equal [:default], Scope.scopes
|
128
|
-
assert_equal [test_predicate3], Scope[:default].predicates
|
129
|
-
assert_nil Scope[:scope1 ]
|
130
|
-
assert_nil Scope[:scope2 ]
|
127
|
+
assert_equal [:default], Porolog::Scope.scopes
|
128
|
+
assert_equal [test_predicate3], Porolog::Scope[:default].predicates
|
129
|
+
assert_nil Porolog::Scope[:scope1 ]
|
130
|
+
assert_nil Porolog::Scope[:scope2 ]
|
131
131
|
end
|
132
132
|
|
133
133
|
end
|
@@ -135,14 +135,14 @@ describe 'Porolog' do
|
|
135
135
|
describe '.[]' do
|
136
136
|
|
137
137
|
it 'should provide access to a scope by name' do
|
138
|
-
alpha = Scope.new :alpha
|
139
|
-
bravo = Scope.new :bravo
|
140
|
-
carly = Scope.new :carly
|
138
|
+
alpha = Porolog::Scope.new :alpha
|
139
|
+
bravo = Porolog::Scope.new :bravo
|
140
|
+
carly = Porolog::Scope.new :carly
|
141
141
|
|
142
|
-
assert_equal alpha, Scope[:alpha]
|
143
|
-
assert_equal bravo, Scope[:bravo]
|
144
|
-
assert_equal carly, Scope[:carly]
|
145
|
-
assert_nil Scope[:delta]
|
142
|
+
assert_equal alpha, Porolog::Scope[:alpha]
|
143
|
+
assert_equal bravo, Porolog::Scope[:bravo]
|
144
|
+
assert_equal carly, Porolog::Scope[:carly]
|
145
|
+
assert_nil Porolog::Scope[:delta]
|
146
146
|
end
|
147
147
|
|
148
148
|
end
|
@@ -150,14 +150,14 @@ describe 'Porolog' do
|
|
150
150
|
describe '.new' do
|
151
151
|
|
152
152
|
it 'should not create duplicate scopes (with the same name)' do
|
153
|
-
Scope.new :duplicate
|
154
|
-
Scope.new :duplicate
|
155
|
-
Scope.new :duplicate
|
156
|
-
Scope.new :duplicate
|
153
|
+
Porolog::Scope.new :duplicate
|
154
|
+
Porolog::Scope.new :duplicate
|
155
|
+
Porolog::Scope.new :duplicate
|
156
|
+
Porolog::Scope.new :duplicate
|
157
157
|
|
158
|
-
assert_equal 2, Scope.scopes.size
|
159
|
-
assert_equal 1, Scope.scopes.count(:duplicate)
|
160
|
-
assert_equal [:default, :duplicate], Scope.scopes
|
158
|
+
assert_equal 2, Porolog::Scope.scopes.size
|
159
|
+
assert_equal 1, Porolog::Scope.scopes.count(:duplicate)
|
160
|
+
assert_equal [:default, :duplicate], Porolog::Scope.scopes
|
161
161
|
end
|
162
162
|
|
163
163
|
end
|
@@ -165,15 +165,15 @@ describe 'Porolog' do
|
|
165
165
|
describe '#initialize' do
|
166
166
|
|
167
167
|
it 'should keep track of created scopes' do
|
168
|
-
Scope.new :alpha
|
169
|
-
Scope.new :bravo
|
170
|
-
Scope.new :carly
|
168
|
+
Porolog::Scope.new :alpha
|
169
|
+
Porolog::Scope.new :bravo
|
170
|
+
Porolog::Scope.new :carly
|
171
171
|
|
172
|
-
assert_equal [:default,:alpha,:bravo,:carly], Scope.scopes
|
172
|
+
assert_equal [:default,:alpha,:bravo,:carly], Porolog::Scope.scopes
|
173
173
|
end
|
174
174
|
|
175
175
|
it 'should create scopes with no predicates' do
|
176
|
-
scope = Scope.new('test_scope_name')
|
176
|
+
scope = Porolog::Scope.new('test_scope_name')
|
177
177
|
|
178
178
|
assert_respond_to scope, :predicates
|
179
179
|
assert_equal [], scope.predicates
|
@@ -184,7 +184,7 @@ describe 'Porolog' do
|
|
184
184
|
describe '#name' do
|
185
185
|
|
186
186
|
it 'should create scopes with a name attribute' do
|
187
|
-
scope = Scope.new('test_scope_name')
|
187
|
+
scope = Porolog::Scope.new('test_scope_name')
|
188
188
|
|
189
189
|
assert_respond_to scope, :name
|
190
190
|
assert_equal 'test_scope_name', scope.name
|
@@ -195,11 +195,11 @@ describe 'Porolog' do
|
|
195
195
|
describe '#predicates' do
|
196
196
|
|
197
197
|
it 'should provide access to all the predicates of a scope' do
|
198
|
-
test_predicate1 = Predicate.new 'test_predicate1', :test
|
199
|
-
test_predicate2 = Predicate.new 'test_predicate2', :test
|
198
|
+
test_predicate1 = Porolog::Predicate.new 'test_predicate1', :test
|
199
|
+
test_predicate2 = Porolog::Predicate.new 'test_predicate2', :test
|
200
200
|
|
201
|
-
assert_respond_to Scope[:test],
|
202
|
-
assert_equal [test_predicate1,test_predicate2], Scope[:test].predicates
|
201
|
+
assert_respond_to Porolog::Scope[:test], :predicates
|
202
|
+
assert_equal [test_predicate1,test_predicate2], Porolog::Scope[:test].predicates
|
203
203
|
end
|
204
204
|
|
205
205
|
end
|
@@ -207,18 +207,18 @@ describe 'Porolog' do
|
|
207
207
|
describe '#[]' do
|
208
208
|
|
209
209
|
it 'should provide access to a predicate of a scope by its name' do
|
210
|
-
test_predicate3 = Predicate.new 'test_predicate3', :test
|
211
|
-
test_predicate4 = Predicate.new 'test_predicate4', :test
|
210
|
+
test_predicate3 = Porolog::Predicate.new 'test_predicate3', :test
|
211
|
+
test_predicate4 = Porolog::Predicate.new 'test_predicate4', :test
|
212
212
|
|
213
|
-
assert_includes Scope[:test].predicates, test_predicate3
|
213
|
+
assert_includes Porolog::Scope[:test].predicates, test_predicate3
|
214
214
|
|
215
|
-
assert_instance_of Class, Scope
|
216
|
-
assert_instance_of Scope,
|
217
|
-
assert_instance_of Predicate,
|
215
|
+
assert_instance_of Class, Porolog::Scope
|
216
|
+
assert_instance_of Porolog::Scope, Porolog::Scope[:test]
|
217
|
+
assert_instance_of Porolog::Predicate, Porolog::Scope[:test][:test_predicate3]
|
218
218
|
|
219
|
-
assert_equal test_predicate3, Scope[:test][:test_predicate3]
|
220
|
-
assert_equal test_predicate3, Scope[:test]['test_predicate3']
|
221
|
-
assert_equal test_predicate4, Scope[:test]['test_predicate4']
|
219
|
+
assert_equal test_predicate3, Porolog::Scope[:test][:test_predicate3]
|
220
|
+
assert_equal test_predicate3, Porolog::Scope[:test]['test_predicate3']
|
221
|
+
assert_equal test_predicate4, Porolog::Scope[:test]['test_predicate4']
|
222
222
|
end
|
223
223
|
|
224
224
|
end
|
@@ -227,7 +227,7 @@ describe 'Porolog' do
|
|
227
227
|
|
228
228
|
it 'should raise an error when trying to put anthing but a Predicate in a Scope' do
|
229
229
|
error = assert_raises(Porolog::Scope::NotPredicateError){
|
230
|
-
scope = Scope.new :scope
|
230
|
+
scope = Porolog::Scope.new :scope
|
231
231
|
|
232
232
|
scope[:predicate] = 'predicate'
|
233
233
|
}
|
@@ -235,18 +235,18 @@ describe 'Porolog' do
|
|
235
235
|
end
|
236
236
|
|
237
237
|
it 'should allow an existing predicate to be assigned to a scope' do
|
238
|
-
test_predicate = Predicate.new 'test_predicate', :test
|
238
|
+
test_predicate = Porolog::Predicate.new 'test_predicate', :test
|
239
239
|
|
240
|
-
scope = Scope.new :scope
|
240
|
+
scope = Porolog::Scope.new :scope
|
241
241
|
|
242
242
|
scope[:predicate] = test_predicate
|
243
243
|
|
244
|
-
assert_equal 3, Scope.scopes.size
|
245
|
-
assert_equal [:default, :test, :scope], Scope.scopes
|
244
|
+
assert_equal 3, Porolog::Scope.scopes.size
|
245
|
+
assert_equal [:default, :test, :scope], Porolog::Scope.scopes
|
246
246
|
|
247
|
-
assert_Scope Scope[:default],
|
248
|
-
assert_Scope Scope[:test],
|
249
|
-
assert_Scope Scope[:scope],
|
247
|
+
assert_Scope Porolog::Scope[:default], :default, []
|
248
|
+
assert_Scope Porolog::Scope[:test], :test, [test_predicate]
|
249
|
+
assert_Scope Porolog::Scope[:scope], :scope, [test_predicate]
|
250
250
|
end
|
251
251
|
|
252
252
|
end
|
data/test/porolog/tail_test.rb
CHANGED
@@ -18,24 +18,24 @@ describe 'Porolog' do
|
|
18
18
|
describe '.new' do
|
19
19
|
|
20
20
|
it 'creates an unknown tail when no value is provided' do
|
21
|
-
tail = Tail.new
|
21
|
+
tail = Porolog::Tail.new
|
22
22
|
|
23
|
-
assert_Tail
|
24
|
-
assert_equal
|
23
|
+
assert_Tail tail, '*...'
|
24
|
+
assert_equal Porolog::UNKNOWN_TAIL, tail.value
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'creates a tail with a value' do
|
28
|
-
tail = Tail.new [2,3,5,7,11,13]
|
28
|
+
tail = Porolog::Tail.new [2,3,5,7,11,13]
|
29
29
|
|
30
|
-
assert_Tail
|
31
|
-
assert_equal
|
30
|
+
assert_Tail tail, '*[2, 3, 5, 7, 11, 13]'
|
31
|
+
assert_equal [2,3,5,7,11,13], tail.value
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'creates a tail with a variable' do
|
35
|
-
tail = Tail.new :x
|
35
|
+
tail = Porolog::Tail.new :x
|
36
36
|
|
37
|
-
assert_Tail
|
38
|
-
assert_equal
|
37
|
+
assert_Tail tail, '*:x'
|
38
|
+
assert_equal :x, tail.value
|
39
39
|
end
|
40
40
|
|
41
41
|
end
|
@@ -51,10 +51,10 @@ describe 'Porolog' do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'returns its value' do
|
54
|
-
tail = Tail.new object
|
54
|
+
tail = Porolog::Tail.new object
|
55
55
|
|
56
|
-
assert_Tail
|
57
|
-
assert_equal
|
56
|
+
assert_Tail tail, '*#<Object:0xXXXXXX>'
|
57
|
+
assert_equal object, tail.value
|
58
58
|
end
|
59
59
|
|
60
60
|
end
|
@@ -62,7 +62,7 @@ describe 'Porolog' do
|
|
62
62
|
describe '#inspect' do
|
63
63
|
|
64
64
|
it 'returns a string showing a splat operation is implied' do
|
65
|
-
tail = Tail.new [2,3,5,7,11,13]
|
65
|
+
tail = Porolog::Tail.new [2,3,5,7,11,13]
|
66
66
|
|
67
67
|
assert_equal '*[2, 3, 5, 7, 11, 13]', tail.inspect
|
68
68
|
end
|
@@ -72,25 +72,25 @@ describe 'Porolog' do
|
|
72
72
|
describe '#variables' do
|
73
73
|
|
74
74
|
it 'returns an empty Array when it was created without arguments' do
|
75
|
-
tail = Tail.new
|
75
|
+
tail = Porolog::Tail.new
|
76
76
|
|
77
77
|
assert_equal [], tail.variables
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'returns an empty Array when it was created with an Array of atomics' do
|
81
|
-
tail = Tail.new [2,3,5,7,11,13]
|
81
|
+
tail = Porolog::Tail.new [2,3,5,7,11,13]
|
82
82
|
|
83
83
|
assert_equal [], tail.variables
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'returns an Array of Symbols when it was created with a Symbol' do
|
87
|
-
tail = Tail.new :t
|
87
|
+
tail = Porolog::Tail.new :t
|
88
88
|
|
89
89
|
assert_equal [:t], tail.variables
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'returns an Array of Symbols when it was created with an Array with embedded Symbols' do
|
93
|
-
tail = Tail.new [2,3,:x,7,[:y,[:z]],13]
|
93
|
+
tail = Porolog::Tail.new [2,3,:x,7,[:y,[:z]],13]
|
94
94
|
|
95
95
|
assert_equal [:x,:y,:z], tail.variables
|
96
96
|
end
|
@@ -100,22 +100,22 @@ describe 'Porolog' do
|
|
100
100
|
describe '#==' do
|
101
101
|
|
102
102
|
it 'returns true for unknown tails' do
|
103
|
-
tail1 = Tail.new
|
104
|
-
tail2 = Tail.new
|
103
|
+
tail1 = Porolog::Tail.new
|
104
|
+
tail2 = Porolog::Tail.new
|
105
105
|
|
106
106
|
assert tail1 == tail2, name
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'returns false for different symbols' do
|
110
|
-
tail1 = Tail.new :t
|
111
|
-
tail2 = Tail.new :x
|
110
|
+
tail1 = Porolog::Tail.new :t
|
111
|
+
tail2 = Porolog::Tail.new :x
|
112
112
|
|
113
113
|
refute tail1 == tail2, name
|
114
114
|
end
|
115
115
|
|
116
116
|
it 'returns true for equal values' do
|
117
|
-
tail1 = Tail.new 12.34
|
118
|
-
tail2 = Tail.new 12.34
|
117
|
+
tail1 = Porolog::Tail.new 12.34
|
118
|
+
tail2 = Porolog::Tail.new 12.34
|
119
119
|
|
120
120
|
assert tail1 == tail2, name
|
121
121
|
end
|
data/test/porolog/value_test.rb
CHANGED
@@ -16,12 +16,12 @@ describe 'Porolog' do
|
|
16
16
|
describe 'Value' do
|
17
17
|
|
18
18
|
let(:goal) { new_goal :generic, [:m, :n] }
|
19
|
-
let(:v) { Value.new 456.123, goal }
|
19
|
+
let(:v) { Porolog::Value.new 456.123, goal }
|
20
20
|
|
21
21
|
describe '.new' do
|
22
22
|
|
23
23
|
it 'should create a new value' do
|
24
|
-
assert_instance_of Value,
|
24
|
+
assert_instance_of Porolog::Value, v
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
@@ -29,22 +29,22 @@ describe 'Porolog' do
|
|
29
29
|
describe '#initialize' do
|
30
30
|
|
31
31
|
it 'should initialize value and goal' do
|
32
|
-
assert_equal 456.123,
|
33
|
-
assert_equal goal,
|
32
|
+
assert_equal 456.123, v.value
|
33
|
+
assert_equal goal, v.goal
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'should raise an error when a goal is not provided' do
|
37
|
-
assert_raises Value::GoalError do
|
38
|
-
Value.new 456.789, 'goal'
|
37
|
+
assert_raises Porolog::Value::GoalError do
|
38
|
+
Porolog::Value.new 456.789, 'goal'
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should copy the value of another Value' do
|
43
|
-
other = Value.new 123.456, goal
|
44
|
-
v = Value.new other, goal
|
43
|
+
other = Porolog::Value.new 123.456, goal
|
44
|
+
v = Porolog::Value.new other, goal
|
45
45
|
|
46
|
-
refute_instance_of Value,
|
47
|
-
assert_equal 123.456,
|
46
|
+
refute_instance_of Porolog::Value, v.value
|
47
|
+
assert_equal 123.456, v.value
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
@@ -52,7 +52,7 @@ describe 'Porolog' do
|
|
52
52
|
describe '#inspect' do
|
53
53
|
|
54
54
|
it 'should show the goal and the value' do
|
55
|
-
assert_equal 'Goal1.456.123',
|
55
|
+
assert_equal 'Goal1.456.123', v.inspect
|
56
56
|
end
|
57
57
|
|
58
58
|
end
|
@@ -60,7 +60,7 @@ describe 'Porolog' do
|
|
60
60
|
describe '#instantiations' do
|
61
61
|
|
62
62
|
it 'should return no instantiations' do
|
63
|
-
assert_equal [],
|
63
|
+
assert_equal [], v.instantiations
|
64
64
|
end
|
65
65
|
|
66
66
|
end
|
@@ -90,19 +90,19 @@ describe 'Porolog' do
|
|
90
90
|
|
91
91
|
describe '#remove' do
|
92
92
|
|
93
|
-
let(:predicate1) { Predicate.new :removal }
|
93
|
+
let(:predicate1) { Porolog::Predicate.new :removal }
|
94
94
|
let(:arguments1) { predicate1.arguments(:m,:n) }
|
95
95
|
let(:goal1) { arguments1.goal }
|
96
96
|
let(:goal2) { arguments1.goal }
|
97
97
|
let(:goal3) { arguments1.goal }
|
98
98
|
let(:goal4) { arguments1.goal }
|
99
99
|
|
100
|
-
let(:variable1) { Variable.new :x, goal1 }
|
101
|
-
let(:variable2) { Variable.new :y, goal2 }
|
102
|
-
let(:variable3) { Variable.new :z, goal3 }
|
103
|
-
let(:variable4) { Variable.new :a, goal1 }
|
104
|
-
let(:value1) { Value.new 'word', goal2 }
|
105
|
-
let(:value2) { Value.new 'draw', goal4 }
|
100
|
+
let(:variable1) { Porolog::Variable.new :x, goal1 }
|
101
|
+
let(:variable2) { Porolog::Variable.new :y, goal2 }
|
102
|
+
let(:variable3) { Porolog::Variable.new :z, goal3 }
|
103
|
+
let(:variable4) { Porolog::Variable.new :a, goal1 }
|
104
|
+
let(:value1) { Porolog::Value.new 'word', goal2 }
|
105
|
+
let(:value2) { Porolog::Value.new 'draw', goal4 }
|
106
106
|
|
107
107
|
before do
|
108
108
|
reset
|
@@ -142,7 +142,6 @@ describe 'Porolog' do
|
|
142
142
|
end
|
143
143
|
|
144
144
|
it 'should remove all instantiations case 1: remove value1' do
|
145
|
-
|
146
145
|
value1.remove
|
147
146
|
|
148
147
|
assert_Goal_variables goal1, { m: nil, n: nil, x: nil, a: 'draw' }, [
|
@@ -174,7 +173,6 @@ describe 'Porolog' do
|
|
174
173
|
end
|
175
174
|
|
176
175
|
it 'should remove all instantiations case 2: remove value2' do
|
177
|
-
|
178
176
|
value2.remove
|
179
177
|
|
180
178
|
assert_Goal_variables goal1, { m: nil, n: nil, x: 'word', a: nil }, [
|
@@ -241,11 +239,11 @@ describe 'Porolog' do
|
|
241
239
|
|
242
240
|
describe '#type' do
|
243
241
|
|
244
|
-
let(:float) { Value.new 456.789, goal }
|
245
|
-
let(:integer) { Value.new 456, goal }
|
246
|
-
let(:string) { Value.new 'average', goal }
|
247
|
-
let(:array) { Value.new [1,2,3], goal }
|
248
|
-
let(:object) { Value.new Object.new, goal }
|
242
|
+
let(:float) { Porolog::Value.new 456.789, goal }
|
243
|
+
let(:integer) { Porolog::Value.new 456, goal }
|
244
|
+
let(:string) { Porolog::Value.new 'average', goal }
|
245
|
+
let(:array) { Porolog::Value.new [1,2,3], goal }
|
246
|
+
let(:object) { Porolog::Value.new Object.new, goal }
|
249
247
|
|
250
248
|
it 'should return atomic for Float' do
|
251
249
|
assert_equal :atomic, float.type
|
@@ -272,22 +270,22 @@ describe 'Porolog' do
|
|
272
270
|
describe '#==' do
|
273
271
|
|
274
272
|
it 'should return false for Values of different types' do
|
275
|
-
v1 = Value.new 456.789, goal
|
276
|
-
v2 = Value.new 'average', goal
|
273
|
+
v1 = Porolog::Value.new 456.789, goal
|
274
|
+
v2 = Porolog::Value.new 'average', goal
|
277
275
|
|
278
276
|
refute v1 == v2, "#{name}: #{v1.value.inspect} == #{v2.value.inspect}"
|
279
277
|
end
|
280
278
|
|
281
279
|
it 'should return false for Values of the same type but different values' do
|
282
|
-
v1 = Value.new 456.789, goal
|
283
|
-
v2 = Value.new 123.456, goal
|
280
|
+
v1 = Porolog::Value.new 456.789, goal
|
281
|
+
v2 = Porolog::Value.new 123.456, goal
|
284
282
|
|
285
283
|
refute v1 == v2, "#{name}: #{v1.value.inspect} == #{v2.value.inspect}"
|
286
284
|
end
|
287
285
|
|
288
286
|
it 'should return true for Values of the same type and the same value' do
|
289
|
-
v1 = Value.new 456.789, goal
|
290
|
-
v2 = Value.new 456.789, goal
|
287
|
+
v1 = Porolog::Value.new 456.789, goal
|
288
|
+
v2 = Porolog::Value.new 456.789, goal
|
291
289
|
|
292
290
|
assert v1 == v2, "#{name}: #{v1.value.inspect} == #{v2.value.inspect}"
|
293
291
|
end
|
@@ -297,13 +295,13 @@ describe 'Porolog' do
|
|
297
295
|
describe '#variables' do
|
298
296
|
|
299
297
|
it 'should return an empty Array for a Float value' do
|
300
|
-
float = Value.new 456.789, goal
|
298
|
+
float = Porolog::Value.new 456.789, goal
|
301
299
|
|
302
300
|
assert_equal [], float.variables
|
303
301
|
end
|
304
302
|
|
305
303
|
it 'should return an Array of Symbols for embedded Variables' do
|
306
|
-
array = Value.new [1, :b, 3, ['four', :e, 6], [[:g, 8]]], goal
|
304
|
+
array = Porolog::Value.new [1, :b, 3, ['four', :e, 6], [[:g, 8]]], goal
|
307
305
|
|
308
306
|
assert_equal [:b, :e, :g], array.variables
|
309
307
|
end
|