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/samples_test.rb
CHANGED
@@ -14,7 +14,7 @@ describe 'Porolog' do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'implements delete first predicate' do
|
17
|
-
predicate :delete
|
17
|
+
Porolog::predicate :delete
|
18
18
|
|
19
19
|
delete(:X, [:X]/:T, :T).fact!
|
20
20
|
|
@@ -33,8 +33,8 @@ describe 'Porolog' do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'implements the delete predicate' do
|
36
|
-
builtin :write
|
37
|
-
predicate :delete
|
36
|
+
Porolog::builtin :write
|
37
|
+
Porolog::predicate :delete
|
38
38
|
|
39
39
|
delete(:X, [:X]/:T, :T).fact!
|
40
40
|
delete(:X, [:H]/:T, [:H]/:NT) << [
|
@@ -78,7 +78,7 @@ describe 'Porolog' do
|
|
78
78
|
|
79
79
|
it 'implements the permutation predicate' do
|
80
80
|
warn name
|
81
|
-
predicate :delete, :permutation
|
81
|
+
Porolog::predicate :delete, :permutation
|
82
82
|
|
83
83
|
permutation([],[]).fact!
|
84
84
|
permutation(:List, [:H]/:Permutation) << [
|
@@ -115,8 +115,8 @@ describe 'Porolog' do
|
|
115
115
|
|
116
116
|
it 'solves the Einstein / Zebra riddle' do
|
117
117
|
warn name
|
118
|
-
builtin :is, :member, :is_noteq
|
119
|
-
predicate :same, :not_same, :left, :beside, :houses
|
118
|
+
Porolog::builtin :is, :member, :is_noteq
|
119
|
+
Porolog::predicate :same, :not_same, :left, :beside, :houses
|
120
120
|
|
121
121
|
same(:X,:X).fact!
|
122
122
|
|
@@ -209,8 +209,8 @@ describe 'Porolog' do
|
|
209
209
|
end
|
210
210
|
|
211
211
|
it 'instantiates lists using member and length builtin predicates' do
|
212
|
-
builtin :member, :length
|
213
|
-
predicate :lists
|
212
|
+
Porolog::builtin :member, :length
|
213
|
+
Porolog::predicate :lists
|
214
214
|
|
215
215
|
lists(:L) << [
|
216
216
|
member(:N,[1,2,3,4,5]),
|
@@ -238,8 +238,8 @@ describe 'Porolog' do
|
|
238
238
|
end
|
239
239
|
|
240
240
|
it 'implements a prime number search' do
|
241
|
-
builtin :gtr, :is, :noteq, :between
|
242
|
-
predicate :prime, :search_prime
|
241
|
+
Porolog::builtin :gtr, :is, :noteq, :between
|
242
|
+
Porolog::predicate :prime, :search_prime
|
243
243
|
|
244
244
|
prime(2).fact!
|
245
245
|
prime(3).fact!
|
@@ -271,7 +271,7 @@ describe 'Porolog' do
|
|
271
271
|
]
|
272
272
|
|
273
273
|
assert_equal known_primes, prime(:number).solve_for(:number, max_solutions: 50)
|
274
|
-
assert_equal 3016, Goal.goal_count
|
274
|
+
assert_equal 3016, Porolog::Goal.goal_count
|
275
275
|
end
|
276
276
|
|
277
277
|
end
|
data/test/test_helper.rb
CHANGED
@@ -21,115 +21,110 @@ require 'mocha/minitest'
|
|
21
21
|
require 'spy/integration'
|
22
22
|
require 'porolog'
|
23
23
|
|
24
|
-
include Porolog
|
25
|
-
|
26
|
-
|
27
24
|
# -- Helpers --
|
28
25
|
def reset
|
29
|
-
Scope.reset
|
30
|
-
Predicate.reset
|
31
|
-
Arguments.reset
|
32
|
-
Rule.reset
|
33
|
-
Goal.reset
|
34
|
-
Instantiation.reset
|
26
|
+
Porolog::Scope.reset
|
27
|
+
Porolog::Predicate.reset
|
28
|
+
Porolog::Arguments.reset
|
29
|
+
Porolog::Rule.reset
|
30
|
+
Porolog::Goal.reset
|
31
|
+
Porolog::Instantiation.reset
|
35
32
|
Porolog::ANONYMOUS[0] = '_a'
|
36
33
|
end
|
37
34
|
|
38
35
|
def assert_Scope(scope, name, predicates)
|
39
|
-
assert_instance_of Scope,
|
40
|
-
assert_equal name,
|
41
|
-
assert_equal predicates,
|
36
|
+
assert_instance_of Porolog::Scope, scope
|
37
|
+
assert_equal name, scope.name
|
38
|
+
assert_equal predicates, scope.predicates
|
42
39
|
end
|
43
40
|
|
44
41
|
def assert_Predicate(predicate, name, rules)
|
45
|
-
assert_instance_of Predicate,
|
46
|
-
assert_equal name,
|
47
|
-
assert_equal rules,
|
42
|
+
assert_instance_of Porolog::Predicate, predicate
|
43
|
+
assert_equal name, predicate.name
|
44
|
+
assert_equal rules, predicate.rules
|
48
45
|
end
|
49
46
|
|
50
47
|
def assert_Arguments(arguments, predicate, args)
|
51
|
-
assert_instance_of Arguments,
|
52
|
-
assert_equal predicate,
|
53
|
-
assert_equal args,
|
48
|
+
assert_instance_of Porolog::Arguments, arguments
|
49
|
+
assert_equal predicate, arguments.predicate.name
|
50
|
+
assert_equal args, arguments.arguments
|
54
51
|
end
|
55
52
|
|
56
53
|
def assert_Rule(rule, predicate, arguments, definition)
|
57
|
-
assert_instance_of Rule,
|
58
|
-
assert_equal predicate,
|
59
|
-
assert_equal arguments,
|
60
|
-
assert_equal definition,
|
54
|
+
assert_instance_of Porolog::Rule, rule
|
55
|
+
assert_equal predicate, rule.arguments.predicate.name
|
56
|
+
assert_equal arguments, rule.arguments.arguments
|
57
|
+
assert_equal definition, rule.definition
|
61
58
|
end
|
62
59
|
|
63
|
-
def assert_Goal(goal, predicate, arguments)
|
64
|
-
assert_instance_of Goal,
|
60
|
+
def assert_Goal(goal, predicate, arguments)
|
61
|
+
assert_instance_of Porolog::Goal, goal
|
65
62
|
assert_equal predicate, goal.arguments.predicate.name
|
66
63
|
assert_equal goal.variablise(arguments), goal.arguments.arguments
|
67
|
-
# TODO: add definition
|
68
|
-
#assert_equal definition, goal.definition
|
69
64
|
end
|
70
65
|
|
71
66
|
def assert_Goal_variables(goal, hash, str)
|
72
|
-
assert_instance_of Goal,
|
73
|
-
assert_equal hash,
|
74
|
-
assert_equal str,
|
67
|
+
assert_instance_of Porolog::Goal, goal
|
68
|
+
assert_equal hash, goal.variables
|
69
|
+
assert_equal str, goal.inspect_variables
|
75
70
|
end
|
76
71
|
|
77
72
|
def assert_Value(value, value_value, goal)
|
78
|
-
assert_instance_of Value,
|
79
|
-
assert_equal value_value,
|
80
|
-
assert_equal goal,
|
73
|
+
assert_instance_of Porolog::Value, value
|
74
|
+
assert_equal value_value, value.value
|
75
|
+
assert_equal goal, value.goal
|
81
76
|
end
|
82
77
|
|
83
78
|
def assert_Variable(variable, name, goal, instantiations, values)
|
84
|
-
assert_instance_of Variable,
|
85
|
-
assert_equal name,
|
86
|
-
assert_equal goal,
|
87
|
-
assert_equal instantiations,
|
88
|
-
assert_equal values,
|
79
|
+
assert_instance_of Porolog::Variable, variable
|
80
|
+
assert_equal name, variable.name
|
81
|
+
assert_equal goal, variable.goal
|
82
|
+
assert_equal instantiations, variable.instantiations
|
83
|
+
assert_equal values, variable.values
|
89
84
|
end
|
90
85
|
|
91
86
|
def assert_Instantiation(instantiation, variable1, variable2, index1, index2)
|
92
|
-
assert_instance_of Instantiation,
|
93
|
-
assert_includes [Variable,Value],
|
94
|
-
assert_includes [Variable,Value],
|
95
|
-
assert_equal variable1,
|
96
|
-
assert_equal variable2,
|
87
|
+
assert_instance_of Porolog::Instantiation, instantiation
|
88
|
+
assert_includes [Porolog::Variable, Porolog::Value], variable1.class
|
89
|
+
assert_includes [Porolog::Variable, Porolog::Value], variable2.class
|
90
|
+
assert_equal variable1, instantiation.variable1
|
91
|
+
assert_equal variable2, instantiation.variable2
|
97
92
|
if index1
|
98
|
-
assert_equal index1,
|
93
|
+
assert_equal index1, instantiation.index1
|
99
94
|
else
|
100
|
-
assert_nil
|
95
|
+
assert_nil instantiation.index1
|
101
96
|
end
|
102
97
|
if index2
|
103
|
-
assert_equal index2,
|
98
|
+
assert_equal index2, instantiation.index2
|
104
99
|
else
|
105
|
-
assert_nil
|
100
|
+
assert_nil instantiation.index2
|
106
101
|
end
|
107
102
|
end
|
108
103
|
|
109
104
|
def assert_Tail(tail, inspect)
|
110
|
-
assert_instance_of Tail,
|
111
|
-
assert_equal inspect,
|
105
|
+
assert_instance_of Porolog::Tail, tail
|
106
|
+
assert_equal inspect, tail.inspect
|
112
107
|
end
|
113
108
|
|
114
109
|
def assert_Array_with_Tail(array, head, inspect)
|
115
|
-
assert_instance_of Array,
|
116
|
-
assert_equal head.size + 1,
|
117
|
-
assert_equal head,
|
118
|
-
assert_Tail array.last,
|
110
|
+
assert_instance_of Array, array
|
111
|
+
assert_equal head.size + 1, array.size
|
112
|
+
assert_equal head, array[0...head.size]
|
113
|
+
assert_Tail array.last, inspect
|
119
114
|
end
|
120
115
|
|
121
116
|
def expect_unify_arrays_with_calls(no_tails, some_tails, all_tails)
|
122
|
-
expects(:unify_arrays_with_no_tails ).times(no_tails)
|
123
|
-
expects(:unify_arrays_with_some_tails).times(some_tails)
|
124
|
-
expects(:unify_arrays_with_all_tails ).times(all_tails)
|
117
|
+
Porolog::expects(:unify_arrays_with_no_tails ).times(no_tails)
|
118
|
+
Porolog::expects(:unify_arrays_with_some_tails).times(some_tails)
|
119
|
+
Porolog::expects(:unify_arrays_with_all_tails ).times(all_tails)
|
125
120
|
end
|
126
121
|
|
127
122
|
def assert_Unify_arrays(arrays, goals, merged, unifications = [])
|
128
|
-
result_merged, result_unifications = unify_arrays(*arrays, *goals)
|
123
|
+
result_merged, result_unifications = Porolog::unify_arrays(*arrays, *goals)
|
129
124
|
|
130
125
|
unifications = unifications.map{|v1,v2,g1,g2|
|
131
|
-
assert_instance_of Goal, g1
|
132
|
-
assert_instance_of Goal, g2
|
126
|
+
assert_instance_of Porolog::Goal, g1
|
127
|
+
assert_instance_of Porolog::Goal, g2
|
133
128
|
[g1.variablise(v1), g2.variablise(v2), g1, g2]
|
134
129
|
}
|
135
130
|
|
@@ -138,7 +133,7 @@ def assert_Unify_arrays(arrays, goals, merged, unifications = [])
|
|
138
133
|
end
|
139
134
|
|
140
135
|
def refute_Unify_arrays(arrays, goals, log = [])
|
141
|
-
result = unify_arrays(*arrays, *goals)
|
136
|
+
result = Porolog::unify_arrays(*arrays, *goals)
|
142
137
|
|
143
138
|
assert_nil result
|
144
139
|
|
@@ -149,7 +144,7 @@ end
|
|
149
144
|
|
150
145
|
|
151
146
|
def new_goal(predicate_name, *arguments_list)
|
152
|
-
predicate = Predicate.new(predicate_name)
|
147
|
+
predicate = Porolog::Predicate.new(predicate_name)
|
153
148
|
arguments = predicate.arguments(*arguments_list)
|
154
149
|
arguments.goal
|
155
150
|
end
|
@@ -158,6 +153,6 @@ def assert_solutions(arguments, expected_solutions, goals: nil)
|
|
158
153
|
solutions = arguments.solve
|
159
154
|
|
160
155
|
assert_equal expected_solutions, solutions
|
161
|
-
assert_equal goals, Goal.goal_count if goals
|
156
|
+
assert_equal goals, Porolog::Goal.goal_count if goals
|
162
157
|
solutions
|
163
158
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: porolog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luis Esteban
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Implements a Prolog inference engine using Plain Old Ruby Objects
|
14
14
|
email:
|