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.
@@ -22,24 +22,24 @@ describe 'Porolog' do
22
22
  let(:variable2) { goal2.variable(:y) }
23
23
  let(:variable3) { goal3.variable(:z) }
24
24
  let(:variable4) { goal3.variable(:v) }
25
- let(:instantiation) { Instantiation.new variable1, nil, variable2, nil }
25
+ let(:instantiation) { Porolog::Instantiation.new variable1, nil, variable2, nil }
26
26
 
27
27
  describe '.reset' do
28
28
 
29
29
  it 'should delete/unregister all instantiations' do
30
- assert_equal 0, Instantiation.instantiations.size
30
+ assert_equal 0, Porolog::Instantiation.instantiations.size
31
31
 
32
- Instantiation.new variable1, nil, variable2, nil
33
- Instantiation.new variable1, nil, variable2, 2
34
- Instantiation.new variable1, nil, variable3, nil
35
- Instantiation.new variable1, 1, variable3, nil
36
- Instantiation.new variable1, nil, variable2, :head
32
+ Porolog::Instantiation.new variable1, nil, variable2, nil
33
+ Porolog::Instantiation.new variable1, nil, variable2, 2
34
+ Porolog::Instantiation.new variable1, nil, variable3, nil
35
+ Porolog::Instantiation.new variable1, 1, variable3, nil
36
+ Porolog::Instantiation.new variable1, nil, variable2, :head
37
37
 
38
- assert_equal 5, Instantiation.instantiations.size
38
+ assert_equal 5, Porolog::Instantiation.instantiations.size
39
39
 
40
- assert Instantiation.reset, name
40
+ assert Porolog::Instantiation.reset, name
41
41
 
42
- assert_equal 0, Instantiation.instantiations.size
42
+ assert_equal 0, Porolog::Instantiation.instantiations.size
43
43
  end
44
44
 
45
45
  end
@@ -47,15 +47,15 @@ describe 'Porolog' do
47
47
  describe '.instantiations' do
48
48
 
49
49
  it 'should be empty to start with' do
50
- assert_equal({}, Instantiation.instantiations)
50
+ assert_equal({}, Porolog::Instantiation.instantiations)
51
51
  end
52
52
 
53
53
  it 'should return all registered instantiations' do
54
- instantiation1 = Instantiation.new variable1, nil, variable2, nil
55
- instantiation2 = Instantiation.new variable1, nil, variable2, 2
56
- instantiation3 = Instantiation.new variable1, nil, variable3, nil
57
- instantiation4 = Instantiation.new variable1, 1, variable3, nil
58
- instantiation5 = Instantiation.new variable2, nil, variable3, nil
54
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, nil
55
+ instantiation2 = Porolog::Instantiation.new variable1, nil, variable2, 2
56
+ instantiation3 = Porolog::Instantiation.new variable1, nil, variable3, nil
57
+ instantiation4 = Porolog::Instantiation.new variable1, 1, variable3, nil
58
+ instantiation5 = Porolog::Instantiation.new variable2, nil, variable3, nil
59
59
 
60
60
  assert_equal(
61
61
  {
@@ -65,7 +65,7 @@ describe 'Porolog' do
65
65
  instantiation4.signature => instantiation4,
66
66
  instantiation5.signature => instantiation5,
67
67
  },
68
- Instantiation.instantiations
68
+ Porolog::Instantiation.instantiations
69
69
  )
70
70
  end
71
71
 
@@ -74,17 +74,17 @@ describe 'Porolog' do
74
74
  describe '.new' do
75
75
 
76
76
  it 'should create a new instantiation' do
77
- instantiation = Instantiation.new variable1, nil, variable2, nil
77
+ instantiation = Porolog::Instantiation.new variable1, nil, variable2, nil
78
78
 
79
- assert_instance_of Instantiation, instantiation
79
+ assert_instance_of Porolog::Instantiation, instantiation
80
80
  end
81
81
 
82
82
  it 'should not create duplicate instantiations' do
83
- instantiation1 = Instantiation.new variable1, nil, variable2, nil
84
- instantiation2 = Instantiation.new variable1, nil, variable2, 2
85
- instantiation3 = Instantiation.new variable1, nil, variable3, nil
86
- instantiation4 = Instantiation.new variable1, 1, variable3, nil
87
- instantiation5 = Instantiation.new variable1, nil, variable2, nil
83
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, nil
84
+ instantiation2 = Porolog::Instantiation.new variable1, nil, variable2, 2
85
+ instantiation3 = Porolog::Instantiation.new variable1, nil, variable3, nil
86
+ instantiation4 = Porolog::Instantiation.new variable1, 1, variable3, nil
87
+ instantiation5 = Porolog::Instantiation.new variable1, nil, variable2, nil
88
88
 
89
89
  assert_equal instantiation1, instantiation5
90
90
  assert_equal(
@@ -94,7 +94,7 @@ describe 'Porolog' do
94
94
  [variable1, 1, variable3, nil] => instantiation4,
95
95
  [variable1, nil, variable3, nil] => instantiation3,
96
96
  },
97
- Instantiation.instantiations
97
+ Porolog::Instantiation.instantiations
98
98
  )
99
99
  end
100
100
 
@@ -103,28 +103,28 @@ describe 'Porolog' do
103
103
  describe '#initialize' do
104
104
 
105
105
  it 'should initialize variable1, variable2, index1, and index2' do
106
- instantiation = Instantiation.new variable1, nil, variable2, nil
106
+ instantiation = Porolog::Instantiation.new variable1, nil, variable2, nil
107
107
 
108
108
  assert_Instantiation instantiation, variable1, variable2, nil, nil
109
109
  end
110
110
 
111
111
  it 'should append itself to its variables' do
112
- instantiation = Instantiation.new variable1, nil, variable2, nil
112
+ instantiation = Porolog::Instantiation.new variable1, nil, variable2, nil
113
113
 
114
114
  assert_equal [instantiation], variable1.instantiations
115
115
  assert_equal [instantiation], variable2.instantiations
116
116
  end
117
117
 
118
118
  it 'should register the instantiation' do
119
- instantiation = Instantiation.new variable1, nil, variable2, nil
119
+ instantiation = Porolog::Instantiation.new variable1, nil, variable2, nil
120
120
 
121
- assert_equal [instantiation], Instantiation.instantiations.values
122
- assert_equal [[variable1, nil, variable2, nil]], Instantiation.instantiations.keys
121
+ assert_equal [instantiation], Porolog::Instantiation.instantiations.values
122
+ assert_equal [[variable1, nil, variable2, nil]], Porolog::Instantiation.instantiations.keys
123
123
  assert_equal(
124
124
  {
125
125
  [variable1, nil, variable2, nil] => instantiation
126
126
  },
127
- Instantiation.instantiations
127
+ Porolog::Instantiation.instantiations
128
128
  )
129
129
  end
130
130
 
@@ -133,8 +133,8 @@ describe 'Porolog' do
133
133
  describe '#signature' do
134
134
 
135
135
  it 'should return the signature of the instantiation' do
136
- instantiation1 = Instantiation.new variable1, nil, variable2, nil
137
- instantiation2 = Instantiation.new variable1, 4, variable2, :head
136
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, nil
137
+ instantiation2 = Porolog::Instantiation.new variable1, 4, variable2, :head
138
138
 
139
139
  assert_equal [variable1, nil, variable2, nil ], instantiation1.signature
140
140
  assert_equal [variable1, 4, variable2, :head], instantiation2.signature
@@ -145,8 +145,8 @@ describe 'Porolog' do
145
145
  describe '#inspect' do
146
146
 
147
147
  it 'should show its variables and their indices' do
148
- instantiation1 = Instantiation.new variable1, nil, variable2, nil
149
- instantiation2 = Instantiation.new variable1, 4, variable2, :head
148
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, nil
149
+ instantiation2 = Porolog::Instantiation.new variable1, 4, variable2, :head
150
150
 
151
151
  assert_equal 'Goal1.:x = Goal2.:y', instantiation1.inspect
152
152
  assert_equal 'Goal1.:x[4] = Goal2.:y[:head]', instantiation2.inspect
@@ -157,7 +157,7 @@ describe 'Porolog' do
157
157
  describe '#remove' do
158
158
 
159
159
  it 'should remove itself from instantiations of both variables' do
160
- instantiation = Instantiation.new variable1, nil, variable2, nil
160
+ instantiation = Porolog::Instantiation.new variable1, nil, variable2, nil
161
161
 
162
162
  assert_equal [instantiation], variable1.instantiations
163
163
  assert_equal [instantiation], variable2.instantiations
@@ -169,7 +169,7 @@ describe 'Porolog' do
169
169
  end
170
170
 
171
171
  it 'should be marked as deleted' do
172
- instantiation = Instantiation.new variable1, nil, variable2, nil
172
+ instantiation = Porolog::Instantiation.new variable1, nil, variable2, nil
173
173
 
174
174
  refute instantiation.deleted?, 'instantiation should not be marked deleted'
175
175
 
@@ -179,27 +179,27 @@ describe 'Porolog' do
179
179
  end
180
180
 
181
181
  it 'should unregister itself' do
182
- assert_equal [], Instantiation.instantiations.values
182
+ assert_equal [], Porolog::Instantiation.instantiations.values
183
183
 
184
- instantiation = Instantiation.new variable1, nil, variable2, nil
184
+ instantiation = Porolog::Instantiation.new variable1, nil, variable2, nil
185
185
 
186
- assert_equal [instantiation], Instantiation.instantiations.values
187
- assert_equal [[variable1, nil, variable2, nil]], Instantiation.instantiations.keys
186
+ assert_equal [instantiation], Porolog::Instantiation.instantiations.values
187
+ assert_equal [[variable1, nil, variable2, nil]], Porolog::Instantiation.instantiations.keys
188
188
  assert_equal(
189
189
  {
190
190
  [variable1, nil, variable2, nil] => instantiation
191
191
  },
192
- Instantiation.instantiations
192
+ Porolog::Instantiation.instantiations
193
193
  )
194
194
 
195
195
  instantiation.remove
196
196
 
197
- assert_equal [], Instantiation.instantiations.values
198
- assert_equal [], Instantiation.instantiations.keys
197
+ assert_equal [], Porolog::Instantiation.instantiations.values
198
+ assert_equal [], Porolog::Instantiation.instantiations.keys
199
199
  assert_equal(
200
200
  {
201
201
  },
202
- Instantiation.instantiations
202
+ Porolog::Instantiation.instantiations
203
203
  )
204
204
  end
205
205
 
@@ -208,8 +208,8 @@ describe 'Porolog' do
208
208
  describe '#other_goal_to' do
209
209
 
210
210
  it 'should return the goal of the other variable' do
211
- instantiation1 = Instantiation.new variable1, nil, variable2, nil
212
- instantiation2 = Instantiation.new variable2, nil, variable3, nil
211
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, nil
212
+ instantiation2 = Porolog::Instantiation.new variable2, nil, variable3, nil
213
213
 
214
214
  assert_equal goal2, instantiation1.other_goal_to(variable1)
215
215
  assert_equal goal1, instantiation1.other_goal_to(variable2)
@@ -224,11 +224,11 @@ describe 'Porolog' do
224
224
  describe '#goals' do
225
225
 
226
226
  it 'should return the goals' do
227
- instantiation1 = Instantiation.new variable1, nil, variable2, nil
228
- instantiation2 = Instantiation.new variable1, 4, variable3, :head
227
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, nil
228
+ instantiation2 = Porolog::Instantiation.new variable1, 4, variable3, :head
229
229
 
230
- assert_equal [goal1, goal2], instantiation1.goals
231
- assert_equal [goal1, goal3], instantiation2.goals
230
+ assert_equal [goal1, goal2], instantiation1.goals
231
+ assert_equal [goal1, goal3], instantiation2.goals
232
232
  end
233
233
 
234
234
  end
@@ -236,8 +236,8 @@ describe 'Porolog' do
236
236
  describe '#variables' do
237
237
 
238
238
  it 'should return both variables' do
239
- instantiation1 = Instantiation.new variable1, nil, variable2, nil
240
- instantiation2 = Instantiation.new variable2, nil, variable3, nil
239
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, nil
240
+ instantiation2 = Porolog::Instantiation.new variable2, nil, variable3, nil
241
241
 
242
242
  assert_equal [variable1,variable2], instantiation1.variables
243
243
  assert_equal [variable2,variable3], instantiation2.variables
@@ -248,52 +248,52 @@ describe 'Porolog' do
248
248
  describe '#values' do
249
249
 
250
250
  it 'should return all values instantiated to its variables' do
251
- instantiation1 = Instantiation.new variable1, nil, variable2, nil
252
- instantiation2 = Instantiation.new variable2, nil, variable3, nil
251
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, nil
252
+ instantiation2 = Porolog::Instantiation.new variable2, nil, variable3, nil
253
253
 
254
- assert_equal [], instantiation1.values
255
- assert_equal [], instantiation2.values
254
+ assert_equal [], instantiation1.values
255
+ assert_equal [], instantiation2.values
256
256
 
257
- variable3.instantiate Value.new('word',goal3)
257
+ variable3.instantiate Porolog::Value.new('word',goal3)
258
258
 
259
- assert_equal ['word'], instantiation1.values
260
- assert_equal ['word'], instantiation2.values
259
+ assert_equal ['word'], instantiation1.values
260
+ assert_equal ['word'], instantiation2.values
261
261
  end
262
262
 
263
263
  it 'should return all indexed values instantiated to its variables' do
264
- instantiation1 = Instantiation.new variable1, nil, variable2, 3
265
- instantiation2 = Instantiation.new variable2, 4, variable3, nil
264
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, 3
265
+ instantiation2 = Porolog::Instantiation.new variable2, 4, variable3, nil
266
266
 
267
- assert_equal [], instantiation1.values
268
- assert_equal [], instantiation2.values
267
+ assert_equal [], instantiation1.values
268
+ assert_equal [], instantiation2.values
269
269
 
270
- variable2.instantiate Value.new([2,3,5,7,11,13,17,19,23],goal2)
270
+ variable2.instantiate Porolog::Value.new([2,3,5,7,11,13,17,19,23],goal2)
271
271
 
272
- assert_equal 7, variable1.value
273
- assert_equal [2,3,5,7,11,13,17,19,23], variable2.value
274
- assert_equal 11, variable3.value
272
+ assert_equal 7, variable1.value
273
+ assert_equal [2,3,5,7,11,13,17,19,23], variable2.value
274
+ assert_equal 11, variable3.value
275
275
 
276
- assert_equal [7], instantiation1.values
277
- assert_equal [11], instantiation2.values
276
+ assert_equal [7], instantiation1.values
277
+ assert_equal [11], instantiation2.values
278
278
 
279
279
  variable2.uninstantiate goal2
280
280
 
281
- assert_equal variable1, variable1.value
282
- assert_equal variable2, variable2.value
283
- assert_equal variable3, variable3.value
281
+ assert_equal variable1, variable1.value
282
+ assert_equal variable2, variable2.value
283
+ assert_equal variable3, variable3.value
284
284
 
285
- assert_equal [], instantiation1.values
286
- assert_equal [], instantiation2.values
285
+ assert_equal [], instantiation1.values
286
+ assert_equal [], instantiation2.values
287
287
 
288
288
  words = %w{two three five seven eleven thirteen seventeen nineteen twenty-three}
289
- variable2.instantiate Value.new(words, goal2)
289
+ variable2.instantiate Porolog::Value.new(words, goal2)
290
290
 
291
- assert_equal 'seven', variable1.value
292
- assert_equal words, variable2.value
293
- assert_equal 'eleven', variable3.value
291
+ assert_equal 'seven', variable1.value
292
+ assert_equal words, variable2.value
293
+ assert_equal 'eleven', variable3.value
294
294
 
295
- assert_equal ['seven'], instantiation1.values
296
- assert_equal ['eleven'], instantiation2.values
295
+ assert_equal ['seven'], instantiation1.values
296
+ assert_equal ['eleven'], instantiation2.values
297
297
  end
298
298
 
299
299
  end
@@ -301,18 +301,18 @@ describe 'Porolog' do
301
301
  describe '#value_indexed' do
302
302
 
303
303
  it 'should return unknown tail when value has an unknown tail and the index is greater than the fixed portion of the list' do
304
- assert_equal UNKNOWN_TAIL, instantiation.value_indexed([2,3,5,7,UNKNOWN_TAIL],99)
304
+ assert_equal Porolog::UNKNOWN_TAIL, instantiation.value_indexed([2, 3, 5, 7, Porolog::UNKNOWN_TAIL], 99)
305
305
  end
306
306
 
307
307
  it 'should return indexed element when value has an unknown tail and the index is less than the fixed portion of the list' do
308
- assert_equal 5, instantiation.value_indexed([2,3,5,7,UNKNOWN_TAIL],2)
308
+ assert_equal 5, instantiation.value_indexed([2, 3, 5, 7, Porolog::UNKNOWN_TAIL], 2)
309
309
  end
310
310
 
311
311
  it 'should return the component when value is a Variable and the index is a Symbol' do
312
- value = goal1.value([2,3,5,7,UNKNOWN_TAIL])
312
+ value = goal1.value([2, 3, 5, 7, Porolog::UNKNOWN_TAIL])
313
313
 
314
- assert_equal 2, instantiation.value_indexed(value,:head)
315
- assert_equal [3,5,7,UNKNOWN_TAIL], instantiation.value_indexed(value,:tail)
314
+ assert_equal 2, instantiation.value_indexed(value,:head)
315
+ assert_equal [3, 5, 7, Porolog::UNKNOWN_TAIL], instantiation.value_indexed(value,:tail)
316
316
  end
317
317
 
318
318
  it 'should return nil when value is nil' do
@@ -362,17 +362,17 @@ describe 'Porolog' do
362
362
  end
363
363
 
364
364
  it 'should raise an error when index is unexpected' do
365
- assert_raises Instantiation::UnhandledIndexError do
365
+ assert_raises Porolog::Instantiation::UnhandledIndexError do
366
366
  assert_equal [2,3,5,7,11], instantiation.value_indexed([2,3,5,7,11],12.34)
367
367
  end
368
- assert_raises Instantiation::UnhandledIndexError do
368
+ assert_raises Porolog::Instantiation::UnhandledIndexError do
369
369
  assert_equal [2,3,5,7,11], instantiation.value_indexed([2,3,5,7,11],'hello')
370
370
  end
371
- assert_raises Instantiation::UnhandledIndexError do
371
+ assert_raises Porolog::Instantiation::UnhandledIndexError do
372
372
  assert_equal [2,3,5,7,11], instantiation.value_indexed([2,3,5,7,11],Object)
373
373
  end
374
374
  object = Object.new
375
- assert_raises Instantiation::UnhandledIndexError do
375
+ assert_raises Porolog::Instantiation::UnhandledIndexError do
376
376
  assert_equal [2,3,5,7,11], instantiation.value_indexed([2,3,5,7,11],object)
377
377
  end
378
378
  end
@@ -382,8 +382,8 @@ describe 'Porolog' do
382
382
  describe '#values_for' do
383
383
 
384
384
  it 'should return all values instantiated to the specified variable' do
385
- instantiation1 = Instantiation.new variable1, nil, variable2, nil
386
- instantiation2 = Instantiation.new variable2, nil, variable3, nil
385
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, nil
386
+ instantiation2 = Porolog::Instantiation.new variable2, nil, variable3, nil
387
387
 
388
388
  assert_equal [], instantiation1.values_for(variable1)
389
389
  assert_equal [], instantiation1.values_for(variable2)
@@ -392,7 +392,7 @@ describe 'Porolog' do
392
392
  assert_equal [], instantiation2.values_for(variable2)
393
393
  assert_equal [], instantiation2.values_for(variable3)
394
394
 
395
- variable3.instantiate Value.new('word',goal3)
395
+ variable3.instantiate Porolog::Value.new('word',goal3)
396
396
 
397
397
  assert_Goal_variables goal1, { m: nil, n: nil, x: 'word' }, [
398
398
  'Goal1.:m',
@@ -428,15 +428,15 @@ describe 'Porolog' do
428
428
  end
429
429
 
430
430
  it 'should return all indexed values instantiated to its variables' do
431
- instantiation1 = Instantiation.new variable1, nil, variable2, 3
432
- instantiation2 = Instantiation.new variable2, 4, variable3, nil
431
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, 3
432
+ instantiation2 = Porolog::Instantiation.new variable2, 4, variable3, nil
433
433
 
434
434
  assert_equal [], instantiation1.values_for(variable1)
435
435
  assert_equal [], instantiation1.values_for(variable2)
436
436
  assert_equal [], instantiation2.values_for(variable2)
437
437
  assert_equal [], instantiation2.values_for(variable3)
438
438
 
439
- variable2.instantiate Value.new([2,3,5,7,11,13,17,19,23],goal2)
439
+ variable2.instantiate Porolog::Value.new([2,3,5,7,11,13,17,19,23],goal2)
440
440
 
441
441
  assert_equal 7, variable1.value
442
442
  assert_equal [2,3,5,7,11,13,17,19,23], variable2.value
@@ -457,7 +457,7 @@ describe 'Porolog' do
457
457
  assert_equal [], instantiation2.values
458
458
 
459
459
  words = %w{two three five seven eleven thirteen seventeen nineteen twenty-three}
460
- variable2.instantiate Value.new(words, goal2)
460
+ variable2.instantiate Porolog::Value.new(words, goal2)
461
461
 
462
462
  assert_equal 'seven', variable1.value
463
463
  assert_equal words, variable2.value
@@ -468,9 +468,9 @@ describe 'Porolog' do
468
468
  end
469
469
 
470
470
  it 'should not infinitely recurse' do
471
- instantiation1 = Instantiation.new variable1, nil, variable2, nil
472
- instantiation2 = Instantiation.new variable2, nil, variable3, nil
473
- instantiation3 = Instantiation.new variable3, nil, variable1, nil
471
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, nil
472
+ instantiation2 = Porolog::Instantiation.new variable2, nil, variable3, nil
473
+ instantiation3 = Porolog::Instantiation.new variable3, nil, variable1, nil
474
474
 
475
475
  assert_equal [], instantiation1.values_for(variable1)
476
476
  assert_equal [], instantiation1.values_for(variable2)
@@ -481,13 +481,13 @@ describe 'Porolog' do
481
481
  end
482
482
 
483
483
  it 'should return an uninstantiated tail when the head is known only' do
484
- instantiation1 = Instantiation.new variable1, :head, variable2, nil
485
- instantiation2 = Instantiation.new variable2, nil, variable3, nil
486
- instantiation3 = Instantiation.new variable3, nil, variable4, nil
484
+ instantiation1 = Porolog::Instantiation.new variable1, :head, variable2, nil
485
+ instantiation2 = Porolog::Instantiation.new variable2, nil, variable3, nil
486
+ instantiation3 = Porolog::Instantiation.new variable3, nil, variable4, nil
487
487
 
488
488
  goal3.instantiate :v, 'head', goal3
489
489
 
490
- assert_Goal_variables goal1, { m: nil, n: nil, x: [goal3.value('head'), UNKNOWN_TAIL] }, [
490
+ assert_Goal_variables goal1, { m: nil, n: nil, x: [goal3.value('head'), Porolog::UNKNOWN_TAIL] }, [
491
491
  'Goal1.:m',
492
492
  'Goal1.:n',
493
493
  'Goal1.:x',
@@ -512,7 +512,7 @@ describe 'Porolog' do
512
512
  ' Goal3."head"',
513
513
  ].join("\n")
514
514
 
515
- assert_equal [['head', UNKNOWN_TAIL]], instantiation1.values_for(variable1)
515
+ assert_equal [['head', Porolog::UNKNOWN_TAIL]], instantiation1.values_for(variable1)
516
516
  assert_equal [], instantiation1.values_for(variable2)
517
517
  assert_equal ['head'], instantiation2.values_for(variable2)
518
518
  assert_equal [], instantiation2.values_for(variable3)
@@ -521,9 +521,9 @@ describe 'Porolog' do
521
521
  end
522
522
 
523
523
  it 'should return an uninstantiated head when the tail is known only' do
524
- instantiation1 = Instantiation.new variable1, :tail, variable2, nil
525
- instantiation2 = Instantiation.new variable2, nil, variable3, nil
526
- instantiation3 = Instantiation.new variable3, nil, variable4, nil
524
+ instantiation1 = Porolog::Instantiation.new variable1, :tail, variable2, nil
525
+ instantiation2 = Porolog::Instantiation.new variable2, nil, variable3, nil
526
+ instantiation3 = Porolog::Instantiation.new variable3, nil, variable4, nil
527
527
 
528
528
  goal3.instantiate :v, ['this','is','the','tail'], goal3
529
529
 
@@ -561,13 +561,13 @@ describe 'Porolog' do
561
561
  end
562
562
 
563
563
  it 'should return a list with uninstantiated elements and tail with the value at the index' do
564
- instantiation1 = Instantiation.new variable1, 3, variable2, nil
565
- instantiation2 = Instantiation.new variable2, nil, variable3, nil
566
- instantiation3 = Instantiation.new variable3, nil, variable4, nil
564
+ instantiation1 = Porolog::Instantiation.new variable1, 3, variable2, nil
565
+ instantiation2 = Porolog::Instantiation.new variable2, nil, variable3, nil
566
+ instantiation3 = Porolog::Instantiation.new variable3, nil, variable4, nil
567
567
 
568
568
  goal3.instantiate :v, 45.9, goal3
569
569
 
570
- assert_Goal_variables goal1, { m: nil, n: nil, x: [nil, nil, nil, goal3.value(45.9), UNKNOWN_TAIL] }, [
570
+ assert_Goal_variables goal1, { m: nil, n: nil, x: [nil, nil, nil, goal3.value(45.9), Porolog::UNKNOWN_TAIL] }, [
571
571
  'Goal1.:m',
572
572
  'Goal1.:n',
573
573
  'Goal1.:x',
@@ -592,18 +592,18 @@ describe 'Porolog' do
592
592
  ' Goal3.45.9',
593
593
  ].join("\n")
594
594
 
595
- assert_equal [[nil, nil, nil, 45.9, UNKNOWN_TAIL]], instantiation1.values_for(variable1)
596
- assert_equal [], instantiation1.values_for(variable2)
597
- assert_equal [goal3.value(45.9)], instantiation2.values_for(variable2)
598
- assert_equal [], instantiation2.values_for(variable3)
599
- assert_equal [goal3.value(45.9)], instantiation3.values_for(variable3)
600
- assert_equal [], instantiation3.values_for(variable4)
595
+ assert_equal [[nil, nil, nil, 45.9, Porolog::UNKNOWN_TAIL]], instantiation1.values_for(variable1)
596
+ assert_equal [], instantiation1.values_for(variable2)
597
+ assert_equal [goal3.value(45.9)], instantiation2.values_for(variable2)
598
+ assert_equal [], instantiation2.values_for(variable3)
599
+ assert_equal [goal3.value(45.9)], instantiation3.values_for(variable3)
600
+ assert_equal [], instantiation3.values_for(variable4)
601
601
  end
602
602
 
603
603
  it 'should return the value of variable1 when the specified variable is variable2 and variable1 is not a Variable' do
604
604
  value1 = goal1.value('titanium')
605
605
 
606
- instantiation1 = Instantiation.new value1, nil, variable3, nil
606
+ instantiation1 = Porolog::Instantiation.new value1, nil, variable3, nil
607
607
 
608
608
  assert_equal [value1], instantiation1.values_for(variable3)
609
609
  end
@@ -614,7 +614,7 @@ describe 'Porolog' do
614
614
  instantiation1 = variable1.instantiate variable2, nil, :flathead
615
615
  variable2.instantiate value1
616
616
 
617
- assert_equal [[1,2,3,4,UNKNOWN_TAIL]], instantiation1.values_for(variable1)
617
+ assert_equal [[1, 2, 3, 4, Porolog::UNKNOWN_TAIL]], instantiation1.values_for(variable1)
618
618
  end
619
619
 
620
620
  it 'should return the value of variable1 given the instantiation of the flathead of variable2' do
@@ -623,7 +623,7 @@ describe 'Porolog' do
623
623
  instantiation1 = variable2.instantiate variable1, :flathead
624
624
  variable2.instantiate value1
625
625
 
626
- assert_equal [[1,2,3,4,UNKNOWN_TAIL]], instantiation1.values_for(variable1)
626
+ assert_equal [[1, 2, 3, 4, Porolog::UNKNOWN_TAIL]], instantiation1.values_for(variable1)
627
627
  end
628
628
 
629
629
  it 'should return the value of variable1 given the instantiation of the flattail of variable1' do
@@ -632,7 +632,7 @@ describe 'Porolog' do
632
632
  instantiation1 = variable1.instantiate variable2, nil, :flattail
633
633
  variable2.instantiate value1
634
634
 
635
- assert_equal [[UNKNOWN_TAIL,1,2,3,4]], instantiation1.values_for(variable1)
635
+ assert_equal [[Porolog::UNKNOWN_TAIL, 1, 2, 3, 4]], instantiation1.values_for(variable1)
636
636
  end
637
637
 
638
638
  it 'should return the value of variable1 given the instantiation of the flattail of variable2' do
@@ -641,7 +641,7 @@ describe 'Porolog' do
641
641
  instantiation1 = variable2.instantiate variable1, :flattail
642
642
  variable2.instantiate value1
643
643
 
644
- assert_equal [[UNKNOWN_TAIL,1,2,3,4]], instantiation1.values_for(variable1)
644
+ assert_equal [[Porolog::UNKNOWN_TAIL, 1, 2, 3, 4]], instantiation1.values_for(variable1)
645
645
  end
646
646
 
647
647
  end
@@ -663,11 +663,11 @@ describe 'Porolog' do
663
663
  describe 'when index is Integer' do
664
664
 
665
665
  it 'should return nil for nil value' do
666
- assert_nil instantiation.value_at_index(nil,5)
666
+ assert_nil instantiation.value_at_index(nil,5)
667
667
  end
668
668
 
669
669
  it 'should return an Array for an Integer indexed value' do
670
- assert_equal [nil,nil,nil,nil,nil,'word',UNKNOWN_TAIL], instantiation.value_at_index('word',5)
670
+ assert_equal [nil, nil, nil, nil, nil, 'word', Porolog::UNKNOWN_TAIL], instantiation.value_at_index('word',5)
671
671
  end
672
672
 
673
673
  end
@@ -675,16 +675,16 @@ describe 'Porolog' do
675
675
  describe 'when index is Symbol' do
676
676
 
677
677
  it 'should return an Array for a head indexed value' do
678
- assert_equal [['word','from','list'],UNKNOWN_TAIL], instantiation.value_at_index(['word','from','list'],:head)
678
+ assert_equal [['word', 'from', 'list'], Porolog::UNKNOWN_TAIL], instantiation.value_at_index(['word','from','list'],:head)
679
679
  end
680
680
 
681
681
  it 'should return an Array for a tail indexed value' do
682
- assert_equal [nil,'word','from','list'], instantiation.value_at_index(['word','from','list'],:tail)
682
+ assert_equal [nil, 'word', 'from', 'list'], instantiation.value_at_index(['word','from','list'],:tail)
683
683
  end
684
684
 
685
685
  it 'should return an error for an unrecognised symbol indexed value' do
686
- assert_raises Instantiation::UnhandledIndexError do
687
- assert_equal :error, instantiation.value_at_index(['word','from','list'],:size)
686
+ assert_raises Porolog::Instantiation::UnhandledIndexError do
687
+ assert_equal :error, instantiation.value_at_index(['word','from','list'],:size)
688
688
  end
689
689
  end
690
690
 
@@ -693,19 +693,19 @@ describe 'Porolog' do
693
693
  describe 'when index is Array' do
694
694
 
695
695
  it 'should return an Array for a tail indexed value' do
696
- assert_equal [nil,'word','from','list'], instantiation.value_at_index(['word','from','list'],[])
696
+ assert_equal [nil,'word','from','list'], instantiation.value_at_index(['word','from','list'],[])
697
697
  end
698
698
 
699
699
  it 'should return an Array for a tail indexed value' do
700
- assert_equal [['word','from','list'], UNKNOWN_TAIL], instantiation.value_at_index(['word','from','list'],[1])
700
+ assert_equal [['word','from','list'], Porolog::UNKNOWN_TAIL], instantiation.value_at_index(['word','from','list'],[1])
701
701
  end
702
702
 
703
703
  it 'should return an Array for a tail indexed value' do
704
- assert_equal [['word','from','list'], UNKNOWN_TAIL], instantiation.value_at_index(['word','from','list'],[2])
704
+ assert_equal [['word','from','list'], Porolog::UNKNOWN_TAIL], instantiation.value_at_index(['word','from','list'],[2])
705
705
  end
706
706
 
707
707
  it 'should return an Array for a tail indexed value' do
708
- assert_equal [['word','from','list'], UNKNOWN_TAIL], instantiation.value_at_index(['word','from','list'],[-2])
708
+ assert_equal [['word','from','list'], Porolog::UNKNOWN_TAIL], instantiation.value_at_index(['word','from','list'],[-2])
709
709
  end
710
710
 
711
711
  end
@@ -713,7 +713,7 @@ describe 'Porolog' do
713
713
  describe 'when index is Float' do
714
714
 
715
715
  it 'should return an error for an unrecognised symbol indexed value' do
716
- assert_raises Instantiation::UnhandledIndexError do
716
+ assert_raises Porolog::Instantiation::UnhandledIndexError do
717
717
  assert_equal ['word','from','list'], instantiation.value_at_index(['word','from','list'],2.3)
718
718
  end
719
719
  end
@@ -721,8 +721,8 @@ describe 'Porolog' do
721
721
  end
722
722
 
723
723
  it 'should return all values instantiated to the specified variable' do
724
- instantiation1 = Instantiation.new variable1, nil, variable2, nil
725
- instantiation2 = Instantiation.new variable2, nil, variable3, nil
724
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, nil
725
+ instantiation2 = Porolog::Instantiation.new variable2, nil, variable3, nil
726
726
 
727
727
  assert_equal [], instantiation1.values_for(variable1)
728
728
  assert_equal [], instantiation1.values_for(variable2)
@@ -731,7 +731,7 @@ describe 'Porolog' do
731
731
  assert_equal [], instantiation2.values_for(variable2)
732
732
  assert_equal [], instantiation2.values_for(variable3)
733
733
 
734
- variable3.instantiate Value.new('word',goal3)
734
+ variable3.instantiate Porolog::Value.new('word',goal3)
735
735
 
736
736
  assert_Goal_variables goal1, { m: nil, n: nil, x: 'word' }, [
737
737
  'Goal1.:m',
@@ -769,15 +769,15 @@ describe 'Porolog' do
769
769
  end
770
770
 
771
771
  it 'should return all indexed values instantiated to its variables' do
772
- instantiation1 = Instantiation.new variable1, nil, variable2, 3
773
- instantiation2 = Instantiation.new variable2, 4, variable3, nil
772
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, 3
773
+ instantiation2 = Porolog::Instantiation.new variable2, 4, variable3, nil
774
774
 
775
775
  assert_equal [], instantiation1.values_for(variable1)
776
776
  assert_equal [], instantiation1.values_for(variable2)
777
777
  assert_equal [], instantiation2.values_for(variable2)
778
778
  assert_equal [], instantiation2.values_for(variable3)
779
779
 
780
- variable2.instantiate Value.new([2,3,5,7,11,13,17,19,23],goal2)
780
+ variable2.instantiate Porolog::Value.new([2,3,5,7,11,13,17,19,23],goal2)
781
781
 
782
782
  assert_equal 7, variable1.value
783
783
  assert_equal [2,3,5,7,11,13,17,19,23], variable2.value
@@ -798,7 +798,7 @@ describe 'Porolog' do
798
798
  assert_equal [], instantiation2.values
799
799
 
800
800
  words = %w{two three five seven eleven thirteen seventeen nineteen twenty-three}
801
- variable2.instantiate Value.new(words, goal2)
801
+ variable2.instantiate Porolog::Value.new(words, goal2)
802
802
 
803
803
  assert_equal 'seven', variable1.value
804
804
  assert_equal words, variable2.value
@@ -809,9 +809,9 @@ describe 'Porolog' do
809
809
  end
810
810
 
811
811
  it 'should not infinitely recurse' do
812
- instantiation1 = Instantiation.new variable1, nil, variable2, nil
813
- instantiation2 = Instantiation.new variable2, nil, variable3, nil
814
- instantiation3 = Instantiation.new variable3, nil, variable1, nil
812
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, nil
813
+ instantiation2 = Porolog::Instantiation.new variable2, nil, variable3, nil
814
+ instantiation3 = Porolog::Instantiation.new variable3, nil, variable1, nil
815
815
 
816
816
  assert_equal [], instantiation1.values_for(variable1)
817
817
  assert_equal [], instantiation1.values_for(variable2)
@@ -826,35 +826,35 @@ describe 'Porolog' do
826
826
  describe '#without_index_on' do
827
827
 
828
828
  it 'should return true for a variable without an index in the instantiation' do
829
- instantiation = Instantiation.new variable1, nil, variable2, nil
829
+ instantiation = Porolog::Instantiation.new variable1, nil, variable2, nil
830
830
 
831
831
  assert_equal true, instantiation.without_index_on?(variable1)
832
832
  assert_equal true, instantiation.without_index_on?(variable2)
833
833
  end
834
834
 
835
835
  it 'should return correctly when the instantiation has one index' do
836
- instantiation = Instantiation.new variable1, 3, variable2, nil
836
+ instantiation = Porolog::Instantiation.new variable1, 3, variable2, nil
837
837
 
838
838
  assert_equal false, instantiation.without_index_on?(variable1)
839
839
  assert_equal true, instantiation.without_index_on?(variable2)
840
840
  end
841
841
 
842
842
  it 'should return correctly when the instantiation has one index (other one)' do
843
- instantiation = Instantiation.new variable1, nil, variable2, 3
843
+ instantiation = Porolog::Instantiation.new variable1, nil, variable2, 3
844
844
 
845
845
  assert_equal true, instantiation.without_index_on?(variable1)
846
846
  assert_equal false, instantiation.without_index_on?(variable2)
847
847
  end
848
848
 
849
849
  it 'should return false when the instantiation has two indexes' do
850
- instantiation = Instantiation.new variable1, 3, variable2, 3
850
+ instantiation = Porolog::Instantiation.new variable1, 3, variable2, 3
851
851
 
852
852
  assert_equal false, instantiation.without_index_on?(variable1)
853
853
  assert_equal false, instantiation.without_index_on?(variable2)
854
854
  end
855
855
 
856
856
  it 'should return false for a variable not in the instantiation' do
857
- instantiation = Instantiation.new variable1, nil, variable2, nil
857
+ instantiation = Porolog::Instantiation.new variable1, nil, variable2, nil
858
858
 
859
859
  assert_equal false, instantiation.without_index_on?(variable3)
860
860
  end
@@ -874,7 +874,7 @@ describe 'Porolog' do
874
874
  it 'should return true when the goal of variable1 is deleted' do
875
875
  refute instantiation.deleted?, 'instantiation should not be marked deleted'
876
876
 
877
- Goal.goals.delete(goal1)
877
+ Porolog::Goal.goals.delete(goal1)
878
878
 
879
879
  assert instantiation.deleted?, 'instantiation should be marked deleted'
880
880
  end
@@ -882,7 +882,7 @@ describe 'Porolog' do
882
882
  it 'should return true when the goal of variable2 is deleted' do
883
883
  refute instantiation.deleted?, 'instantiation should not be marked deleted'
884
884
 
885
- Goal.goals.delete(goal2)
885
+ Porolog::Goal.goals.delete(goal2)
886
886
 
887
887
  assert instantiation.deleted?, 'instantiation should be marked deleted'
888
888
  end
@@ -892,8 +892,8 @@ describe 'Porolog' do
892
892
  describe '#belongs_to?' do
893
893
 
894
894
  it 'should correctly determine the relationship between an instantition and a goal' do
895
- instantiation1 = Instantiation.new variable1, nil, variable2, nil
896
- instantiation2 = Instantiation.new variable2, nil, variable3, nil
895
+ instantiation1 = Porolog::Instantiation.new variable1, nil, variable2, nil
896
+ instantiation2 = Porolog::Instantiation.new variable2, nil, variable3, nil
897
897
 
898
898
  assert instantiation1.belongs_to?(goal1), 'instantiation1 should belong to goal1'
899
899
  assert instantiation1.belongs_to?(goal2), 'instantiation1 should belong to goal2'