rubylog 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +10 -0
- data/README.rdoc +1 -1
- data/RELEASE_NOTES.rdoc +7 -4
- data/VERSION +1 -1
- data/{examples → benchmark}/benchmark.rb +1 -0
- data/{examples → benchmark}/benchmark/compiled_not_indexed.rb +0 -0
- data/{examples → benchmark}/benchmark/compiled_sequence_indexed.rb +0 -0
- data/{examples → benchmark}/benchmark/indexed_procedure.rb +0 -0
- data/{examples → benchmark}/benchmark/prolog.rb +0 -0
- data/benchmark/benchmark/pure.rb +28 -0
- data/bin/rubylog +14 -0
- data/examples/a_plus_b.rb +2 -2
- data/examples/dcg.rb +22 -26
- data/examples/dcg2.rb +25 -30
- data/examples/divisors.rb +1 -3
- data/examples/factorial.rb +8 -15
- data/examples/file_search.rb +14 -13
- data/examples/hanoi.rb +1 -3
- data/examples/hu/csaladfa.rb +0 -4
- data/examples/n_queens.rb +17 -22
- data/examples/palindrome_detection.rb +1 -2
- data/examples/parsing.rb +19 -23
- data/examples/permutation.rb +1 -3
- data/examples/primality_by_division.rb +2 -2
- data/examples/sieve_of_eratosthenes.rb +2 -2
- data/examples/string_interpolation.rb +0 -3
- data/examples/tracing.rb +0 -4
- data/lib/rubylog/builtins/assumption.rb +2 -1
- data/lib/rubylog/builtins/file_system.rb +1 -1
- data/lib/rubylog/default_context.rb +3 -5
- data/lib/rubylog/mixins/kernel.rb +9 -1
- data/lib/rubylog/rubylog_files.rb +7 -0
- data/rubylog.gemspec +17 -22
- data/spec/inriasuite_spec.rb +851 -847
- data/spec/integration/dsl_spec.rb +32 -29
- data/spec/rspec/rubylog_spec.rb +46 -52
- data/spec/rubylog/assertable_spec.rb +92 -90
- data/spec/rubylog/builtins/arithmetics_spec.rb +92 -90
- data/spec/rubylog/builtins/assumption_spec.rb +59 -57
- data/spec/rubylog/builtins/ensure_spec.rb +6 -4
- data/spec/rubylog/builtins/file_system_spec.rb +41 -39
- data/spec/rubylog/builtins/logic_spec.rb +308 -306
- data/spec/rubylog/builtins/reflection_spec.rb +31 -29
- data/spec/rubylog/builtins/term_spec.rb +62 -60
- data/spec/rubylog/context_modules/demonstration_spec.rb +108 -106
- data/spec/rubylog/context_modules/predicates_spec.rb +29 -27
- data/spec/rubylog/context_modules/thats_spec.rb +77 -75
- data/spec/rubylog/dsl/array_splat_spec.rb +11 -9
- data/spec/rubylog/dsl/indicators_spec.rb +23 -21
- data/spec/rubylog/dsl/primitives_spec.rb +30 -28
- data/spec/rubylog/errors_spec.rb +13 -11
- data/spec/rubylog/interfaces/term_spec.rb +78 -76
- data/spec/rubylog/mixins/array_spec.rb +60 -58
- data/spec/rubylog/mixins/composite_term_spec.rb +55 -53
- data/spec/rubylog/mixins/proc_spec.rb +48 -46
- data/spec/rubylog/mixins/string_spec.rb +45 -43
- data/spec/rubylog/mixins/symbol_spec.rb +7 -5
- data/spec/rubylog/procedure_spec.rb +8 -6
- data/spec/rubylog/rule_spec.rb +10 -8
- data/spec/rubylog/structure_spec.rb +73 -71
- data/spec/rubylog/term_spec.rb +5 -3
- data/spec/rubylog/tracing_spec.rb +35 -33
- data/spec/rubylog/variable_spec.rb +249 -247
- data/spec/spec_helper.rb +4 -0
- metadata +54 -43
- data/examples/benchmark/pure.rb +0 -26
- data/examples/checkmate.rb +0 -88
- data/examples/combination.rb +0 -17
- data/examples/directory_structure_logic.rb +0 -17
- data/examples/dirlist.rb +0 -4
- data/examples/enumerators.rb +0 -30
- data/examples/hello.rb +0 -17
- data/examples/mice.rb +0 -92
- data/examples/mice2.rb +0 -37
- data/examples/object_oriented.rb +0 -14
- data/examples/prefix.rb +0 -13
- data/examples/primitives.rb +0 -26
- data/examples/sudoku.rb +0 -17
- data/spec/integration/theory_as_module_spec.rb +0 -20
- data/spec/integration/theory_as_module_with_include_spec.rb +0 -14
@@ -1,70 +1,72 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
specify do
|
11
|
-
check 4.perfect.false
|
12
|
-
check 5.perfect.false
|
13
|
-
check 6.perfect
|
14
|
-
check 7.perfect.false
|
15
|
-
end
|
3
|
+
module RubylogSpec
|
4
|
+
describe "Assumption builtins", :rubylog=>true do
|
5
|
+
before do
|
6
|
+
predicate_for Integer, ".divides() .perfect"
|
7
|
+
A.divides(B).if { B%A == 0 }
|
8
|
+
N.perfect.if { (A.in{1...N}.and A.divides(N)).map{A}.inject{|a,b|a+b} == N }
|
9
|
+
end
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
check
|
20
|
-
check
|
21
|
-
check
|
22
|
-
check ANY.perfect.assumed.and 4.perfect
|
23
|
-
check ANY.perfect.assumed.and 17.perfect
|
11
|
+
specify do
|
12
|
+
check 4.perfect.false
|
13
|
+
check 5.perfect.false
|
14
|
+
check 6.perfect
|
15
|
+
check 7.perfect.false
|
24
16
|
end
|
25
|
-
end
|
26
17
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
18
|
+
describe "assumed" do
|
19
|
+
specify do
|
20
|
+
check 4.divides(6).assumed.and 6.perfect.false
|
21
|
+
check 2.divides(3).assumed.and 3.perfect
|
22
|
+
check 4.perfect.assumed.and 4.perfect
|
23
|
+
check ANY.perfect.assumed.and 4.perfect
|
24
|
+
check ANY.perfect.assumed.and 17.perfect
|
25
|
+
end
|
32
26
|
end
|
33
|
-
end
|
34
27
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
28
|
+
describe "rejected" do
|
29
|
+
specify do
|
30
|
+
check 4.divides(6).rejected.and 6.perfect
|
31
|
+
check 3.divides(6).rejected.and 6.perfect.false
|
32
|
+
check 2.divides(20).rejected.and 20.perfect
|
33
|
+
end
|
40
34
|
end
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
.map{A}.should == ['milk'] }
|
49
|
-
specify {
|
50
|
-
'John'.likes('water').revoked.true?.should be_false }
|
51
|
-
specify {
|
52
|
-
'John'.likes(X).revoked.map{X}.should == ['milk','beer'] }
|
53
|
-
specify { 'John'.likes(A).map{A}.should == ['milk','beer'] }
|
54
|
-
end
|
36
|
+
describe "revoked" do
|
37
|
+
before do
|
38
|
+
predicate_for String, ".likes()"
|
39
|
+
'John'.likes! 'milk'
|
40
|
+
'John'.likes! 'beer'
|
41
|
+
end
|
55
42
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
43
|
+
specify { 'John'.likes(A).map{A}.should == ['milk','beer'] }
|
44
|
+
specify {
|
45
|
+
'John'.likes('milk').revoked.and('John'.likes(A)) \
|
46
|
+
.map{A}.should == ['beer'] }
|
47
|
+
specify {
|
48
|
+
'John'.likes('beer').revoked.and('John'.likes(A)) \
|
49
|
+
.map{A}.should == ['milk'] }
|
50
|
+
specify {
|
51
|
+
'John'.likes('water').revoked.true?.should be_false }
|
52
|
+
specify {
|
53
|
+
'John'.likes(X).revoked.map{X}.should == ['milk','beer'] }
|
54
|
+
specify { 'John'.likes(A).map{A}.should == ['milk','beer'] }
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "assumed unless" do
|
58
|
+
xspecify
|
59
|
+
end
|
60
|
+
describe "rejected" do
|
61
|
+
xspecify
|
62
|
+
end
|
63
|
+
describe "rejected_if" do
|
64
|
+
xspecify
|
65
|
+
end
|
66
|
+
describe "rejected_unless" do
|
67
|
+
xspecify
|
68
|
+
end
|
67
69
|
end
|
68
|
-
end
|
69
70
|
|
70
71
|
|
72
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module RubylogSpec
|
4
|
+
describe "ensure builtin", :rubylog=>true do
|
5
|
+
k = 6
|
6
|
+
check proc{k=5}.ensure{k=6}.and{k.eql? 5}
|
7
|
+
check {k.eql? 6}
|
8
|
+
end
|
7
9
|
end
|
8
10
|
|
@@ -1,43 +1,45 @@
|
|
1
1
|
require "spec_helper"
|
2
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
|
-
"
|
3
|
+
module RubylogSpec
|
4
|
+
describe "file system builtins", :rubylog=>true do
|
5
|
+
specify "directories are files" do
|
6
|
+
check "./lib".file_in(".")
|
7
|
+
end
|
8
|
+
|
9
|
+
specify ": regular files are files" do
|
10
|
+
check "./README.rdoc".file_in(".")
|
11
|
+
end
|
12
|
+
|
13
|
+
specify ": regular files are not directories" do
|
14
|
+
check "./README.rdoc".dir_in(".").false
|
15
|
+
end
|
16
|
+
|
17
|
+
specify "#filename_in" do
|
18
|
+
check "rubylog.rb".filename_in("lib")
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "#dirname_in" do
|
22
|
+
check "rubylog".dirname_in("lib")
|
23
|
+
end
|
24
|
+
|
25
|
+
specify ": works with variable filename" do
|
26
|
+
A.dir_in(".").map{A}.should include "./lib"
|
27
|
+
end
|
28
|
+
|
29
|
+
specify ": works with variable dir" do
|
30
|
+
"./lib/rubylog.rb".file_in(D).map{D}.should == ["./lib"]
|
31
|
+
end
|
32
|
+
|
33
|
+
specify ": works with function dir" do
|
34
|
+
FN.file_in{"./lib"}.map{FN}.should include "./lib/rubylog.rb"
|
35
|
+
end
|
36
|
+
|
37
|
+
specify ": works with partial strings" do
|
38
|
+
"./lib/#{A}.rb".file_in("./lib").map{A}.should == ["rubylog"]
|
39
|
+
end
|
40
|
+
|
41
|
+
specify "works with nonvars" do
|
42
|
+
"./lib/rubylog.rb".file_in("./lib").to_a.should == [nil]
|
43
|
+
end
|
42
44
|
end
|
43
45
|
end
|
@@ -1,382 +1,384 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
specify "true" do
|
9
|
-
:john.happy.if :true
|
10
|
-
:john.should be_happy
|
11
|
-
end
|
12
|
-
|
13
|
-
specify "fail" do
|
14
|
-
:john.happy.if :fail
|
15
|
-
:john.should_not be_happy
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "false" do
|
19
|
-
specify do
|
20
|
-
:john.happy.if :true.false
|
21
|
-
:john.should_not be_happy
|
3
|
+
module RubylogSpec
|
4
|
+
describe "logic builtins", :rubylog => true do
|
5
|
+
before do
|
6
|
+
predicate_for Symbol, ".likes() .happy"
|
22
7
|
end
|
23
8
|
|
24
|
-
specify do
|
25
|
-
:john.happy.if :
|
9
|
+
specify "true" do
|
10
|
+
:john.happy.if :true
|
26
11
|
:john.should be_happy
|
27
12
|
end
|
28
|
-
end
|
29
13
|
|
30
|
-
|
31
|
-
|
32
|
-
:john.happy.if :fail.and :true
|
14
|
+
specify "fail" do
|
15
|
+
:john.happy.if :fail
|
33
16
|
:john.should_not be_happy
|
34
17
|
end
|
35
18
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
19
|
+
describe "false" do
|
20
|
+
specify do
|
21
|
+
:john.happy.if :true.false
|
22
|
+
:john.should_not be_happy
|
23
|
+
end
|
40
24
|
|
41
|
-
|
42
|
-
|
43
|
-
|
25
|
+
specify do
|
26
|
+
:john.happy.if :fail.false
|
27
|
+
:john.should be_happy
|
28
|
+
end
|
44
29
|
end
|
45
30
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
31
|
+
describe "and" do
|
32
|
+
it "works 1" do
|
33
|
+
:john.happy.if :fail.and :true
|
34
|
+
:john.should_not be_happy
|
35
|
+
end
|
51
36
|
|
37
|
+
it "works 2" do
|
38
|
+
:john.happy.if :true.and :fail
|
39
|
+
:john.should_not be_happy
|
40
|
+
end
|
52
41
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
42
|
+
it "works 3" do
|
43
|
+
:john.happy.if :fail.and :fail
|
44
|
+
:john.should_not be_happy
|
45
|
+
end
|
58
46
|
|
59
|
-
|
60
|
-
|
61
|
-
|
47
|
+
it "works 4" do
|
48
|
+
:john.happy.if :true.and :true
|
49
|
+
:john.should be_happy
|
50
|
+
end
|
62
51
|
end
|
63
52
|
|
64
|
-
it "works 3" do
|
65
|
-
:john.happy.if :fail.or :fail
|
66
|
-
:john.should_not be_happy
|
67
|
-
end
|
68
53
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
54
|
+
describe "or" do
|
55
|
+
it "works 1" do
|
56
|
+
:john.happy.if :fail.or :true
|
57
|
+
:john.should be_happy
|
58
|
+
end
|
74
59
|
|
60
|
+
it "works 2" do
|
61
|
+
:john.happy.if :true.or :fail
|
62
|
+
:john.should be_happy
|
63
|
+
end
|
75
64
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
:john.should be_happy
|
81
|
-
end
|
65
|
+
it "works 3" do
|
66
|
+
:john.happy.if :fail.or :fail
|
67
|
+
:john.should_not be_happy
|
68
|
+
end
|
82
69
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
70
|
+
it "works 4" do
|
71
|
+
:john.happy.if :true.or :true
|
72
|
+
:john.should be_happy
|
73
|
+
end
|
87
74
|
end
|
88
75
|
|
89
|
-
it "works 3" do
|
90
|
-
:john.happy.if :fail
|
91
|
-
:john.happy.if :fail
|
92
|
-
:john.should_not be_happy
|
93
|
-
end
|
94
76
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
77
|
+
describe "branch or" do
|
78
|
+
it "works 1" do
|
79
|
+
:john.happy.if :fail
|
80
|
+
:john.happy.if :true
|
81
|
+
:john.should be_happy
|
82
|
+
end
|
101
83
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
84
|
+
it "works 2" do
|
85
|
+
:john.happy.if :true
|
86
|
+
:john.happy.if :fail
|
87
|
+
:john.should be_happy
|
88
|
+
end
|
107
89
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
90
|
+
it "works 3" do
|
91
|
+
:john.happy.if :fail
|
92
|
+
:john.happy.if :fail
|
93
|
+
:john.should_not be_happy
|
94
|
+
end
|
112
95
|
|
113
|
-
|
114
|
-
|
115
|
-
|
96
|
+
it "works 4" do
|
97
|
+
:john.happy.if :true
|
98
|
+
:john.happy.if :true
|
99
|
+
:john.should be_happy
|
100
|
+
end
|
116
101
|
end
|
117
102
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
103
|
+
describe "iff" do
|
104
|
+
it "works 1" do
|
105
|
+
:john.happy.if :fail.iff :true
|
106
|
+
:john.should_not be_happy
|
107
|
+
end
|
123
108
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
:john.should_not be_happy
|
129
|
-
end
|
130
|
-
it "works with branch or (control)" do
|
131
|
-
:john.happy.if :true.and :fail
|
132
|
-
:john.happy.if :true
|
133
|
-
:john.should be_happy
|
134
|
-
end
|
109
|
+
it "works 2" do
|
110
|
+
:john.happy.if :true.iff :fail
|
111
|
+
:john.should_not be_happy
|
112
|
+
end
|
135
113
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
114
|
+
it "works 3" do
|
115
|
+
:john.happy.if :fail.iff :fail
|
116
|
+
:john.should be_happy
|
117
|
+
end
|
140
118
|
|
141
|
-
|
142
|
-
|
143
|
-
|
119
|
+
it "works 4" do
|
120
|
+
:john.happy.if :true.iff :true
|
121
|
+
:john.should be_happy
|
122
|
+
end
|
144
123
|
end
|
145
124
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
125
|
+
describe "cut" do
|
126
|
+
it "works with branch or" do
|
127
|
+
:john.happy.if :true.and :cut!.and :fail
|
128
|
+
:john.happy.if :true
|
129
|
+
:john.should_not be_happy
|
130
|
+
end
|
131
|
+
it "works with branch or (control)" do
|
132
|
+
:john.happy.if :true.and :fail
|
133
|
+
:john.happy.if :true
|
134
|
+
:john.should be_happy
|
135
|
+
end
|
156
136
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
137
|
+
it "works with or" do
|
138
|
+
:john.happy.if((:true.and :cut!.and :fail).or :true)
|
139
|
+
:john.should_not be_happy
|
140
|
+
end
|
161
141
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
142
|
+
it "works with or (control)" do
|
143
|
+
:john.happy.if((:true.and :fail).or :true)
|
144
|
+
:john.should be_happy
|
145
|
+
end
|
166
146
|
|
167
|
-
|
168
|
-
|
169
|
-
|
147
|
+
it "returns true with branch or" do
|
148
|
+
:john.happy.if :true.and :cut!.and :true
|
149
|
+
:john.happy.if :true
|
150
|
+
:john.should be_happy
|
151
|
+
end
|
152
|
+
it "returns true with branch or (control)" do
|
153
|
+
:john.happy.if :true.and :true
|
154
|
+
:john.happy.if :true
|
155
|
+
:john.should be_happy
|
156
|
+
end
|
170
157
|
|
171
|
-
|
172
|
-
|
173
|
-
|
158
|
+
it "returns true with or" do
|
159
|
+
:john.happy.if((:true.and :cut!.and :true).or :true)
|
160
|
+
:john.should be_happy
|
161
|
+
end
|
174
162
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
end
|
163
|
+
it "returns true with or (control)" do
|
164
|
+
:john.happy.if((:true.and :true).or :true)
|
165
|
+
:john.should be_happy
|
166
|
+
end
|
180
167
|
|
181
|
-
|
182
|
-
|
183
|
-
|
168
|
+
it "works after variable calls" do
|
169
|
+
(A.is(:true).and A.and :cut!.and :fail).or(:true).true?.should be_false
|
170
|
+
end
|
184
171
|
|
185
|
-
|
186
|
-
|
187
|
-
|
172
|
+
it "works after variable calls (control)" do
|
173
|
+
(A.is(:true).and A.and :fail).or(:true).true?.should be_true
|
174
|
+
end
|
188
175
|
|
189
|
-
|
176
|
+
it "works after variable calls (branch or)" do
|
177
|
+
:john.happy.if A.is(:true).and A.and :cut!.and :fail
|
178
|
+
:john.happy.if :true
|
179
|
+
:john.should_not be_happy
|
180
|
+
end
|
190
181
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
:john.likes! :beer
|
195
|
-
|
196
|
-
:jane.likes! :water
|
197
|
-
:jane.likes! :milk
|
198
|
-
:jane.likes! :beer
|
199
|
-
|
200
|
-
:jeff.likes! :water
|
201
|
-
:jeff.likes! :absinth
|
202
|
-
|
203
|
-
:todd.likes! :milk
|
204
|
-
|
205
|
-
@predicates = [:all, :any, :one, :none]
|
206
|
-
@names = :john, :jane, :jeff, :todd
|
207
|
-
@good =
|
208
|
-
[
|
209
|
-
[[1,1,0,0], [0,1,0,0], [0,0,1,0], [0,1,0,1]], # all
|
210
|
-
[[1,1,1,0], [1,1,1,1], [1,1,1,0], [0,1,0,1]], # any
|
211
|
-
[[0,0,1,0], [0,0,1,1], [1,1,0,0], [0,1,0,1]], # one
|
212
|
-
[[0,0,0,1], [0,0,0,0], [0,0,0,1], [1,0,1,0]] # none
|
213
|
-
]
|
214
|
-
end
|
182
|
+
it "works after variable calls with multiple solutions of the variable" do
|
183
|
+
(A.is(B.is(4).or(B.is(6))).and A.and :cut!).map{B}.should == [4]
|
184
|
+
end
|
215
185
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
}}}.should == @good
|
220
|
-
end
|
186
|
+
it "works after variable calls with multiple solutions of the variable (control)" do
|
187
|
+
(A.is(B.is(4).or(B.is(6))).and A).map{B}.should == [4,6]
|
188
|
+
end
|
221
189
|
|
222
|
-
it "mimic well enumerators' predicates" do
|
223
|
-
@predicates.map{|p| @names.map{|n| @names.map{|m|
|
224
|
-
n.likes(K).map{K}.send(:"#{p}?"){|x| m.likes?(x) } ? 1 : 0
|
225
|
-
}}}.should == @good
|
226
190
|
end
|
227
191
|
|
192
|
+
describe "all,any,one,none,every" do
|
193
|
+
before do
|
194
|
+
:john.likes! :water
|
195
|
+
:john.likes! :beer
|
228
196
|
|
197
|
+
:jane.likes! :water
|
198
|
+
:jane.likes! :milk
|
199
|
+
:jane.likes! :beer
|
229
200
|
|
230
|
-
|
231
|
-
|
232
|
-
(:john.likes(X).all(:jane.likes(X))).true?.should be_true
|
233
|
-
(:john.likes(X).all(:jeff.likes(X))).true?.should_not be_true
|
234
|
-
(:john.likes(X).all(:todd.likes(X))).true?.should_not be_true
|
235
|
-
|
236
|
-
(:jane.likes(X).all(:john.likes(X))).true?.should_not be_true
|
237
|
-
(:jane.likes(X).all(:jane.likes(X))).true?.should be_true
|
238
|
-
(:jane.likes(X).all(:jeff.likes(X))).true?.should_not be_true
|
239
|
-
(:jane.likes(X).all(:todd.likes(X))).true?.should_not be_true
|
201
|
+
:jeff.likes! :water
|
202
|
+
:jeff.likes! :absinth
|
240
203
|
|
241
|
-
|
242
|
-
(:jeff.likes(X).all(:jane.likes(X))).true?.should_not be_true
|
243
|
-
(:jeff.likes(X).all(:jeff.likes(X))).true?.should be_true
|
244
|
-
(:jeff.likes(X).all(:todd.likes(X))).true?.should_not be_true
|
204
|
+
:todd.likes! :milk
|
245
205
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
206
|
+
@predicates = [:all, :any, :one, :none]
|
207
|
+
@names = :john, :jane, :jeff, :todd
|
208
|
+
@good =
|
209
|
+
[
|
210
|
+
[[1,1,0,0], [0,1,0,0], [0,0,1,0], [0,1,0,1]], # all
|
211
|
+
[[1,1,1,0], [1,1,1,1], [1,1,1,0], [0,1,0,1]], # any
|
212
|
+
[[0,0,1,0], [0,0,1,1], [1,1,0,0], [0,1,0,1]], # one
|
213
|
+
[[0,0,0,1], [0,0,0,0], [0,0,0,1], [1,0,1,0]] # none
|
214
|
+
]
|
215
|
+
end
|
251
216
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
(:jane.likes(X).all{:john.likes?(X)}).true?.should_not be_true
|
259
|
-
(:jane.likes(X).all{:jane.likes?(X)}).true?.should be_true
|
260
|
-
(:jane.likes(X).all{:jeff.likes?(X)}).true?.should_not be_true
|
261
|
-
(:jane.likes(X).all{:todd.likes?(X)}).true?.should_not be_true
|
262
|
-
|
263
|
-
(:jeff.likes(X).all{:john.likes?(X)}).true?.should_not be_true
|
264
|
-
(:jeff.likes(X).all{:jane.likes?(X)}).true?.should_not be_true
|
265
|
-
(:jeff.likes(X).all{:jeff.likes?(X)}).true?.should be_true
|
266
|
-
(:jeff.likes(X).all{:todd.likes?(X)}).true?.should_not be_true
|
267
|
-
|
268
|
-
(:todd.likes(X).all{:john.likes?(X)}).true?.should_not be_true
|
269
|
-
(:todd.likes(X).all{:jane.likes?(X)}).true?.should be_true
|
270
|
-
(:todd.likes(X).all{:jeff.likes?(X)}).true?.should_not be_true
|
271
|
-
(:todd.likes(X).all{:todd.likes?(X)}).true?.should be_true
|
272
|
-
end
|
217
|
+
it "work" do
|
218
|
+
@predicates.map{|p| @names.map{|n| @names.map{|m|
|
219
|
+
(n.likes(K).send p, m.likes(K)).true? ? 1 : 0
|
220
|
+
}}}.should == @good
|
221
|
+
end
|
273
222
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
end
|
223
|
+
it "mimic well enumerators' predicates" do
|
224
|
+
@predicates.map{|p| @names.map{|n| @names.map{|m|
|
225
|
+
n.likes(K).map{K}.send(:"#{p}?"){|x| m.likes?(x) } ? 1 : 0
|
226
|
+
}}}.should == @good
|
227
|
+
end
|
280
228
|
|
281
|
-
it "one, any, none can be called unarily" do
|
282
|
-
one(:john.likes(X)).true?.should_not be_true
|
283
|
-
one(:jane.likes(X)).true?.should_not be_true
|
284
|
-
one(:jeff.likes(X)).true?.should_not be_true
|
285
|
-
one(:todd.likes(X)).true?.should be_true
|
286
|
-
one(:jim.likes(X)).true?.should_not be_true
|
287
|
-
|
288
|
-
any(:john.likes(X)).true?.should be_true
|
289
|
-
any(:jane.likes(X)).true?.should be_true
|
290
|
-
any(:jeff.likes(X)).true?.should be_true
|
291
|
-
any(:todd.likes(X)).true?.should be_true
|
292
|
-
any(:jim.likes(X)).true?.should_not be_true
|
293
|
-
|
294
|
-
none(:john.likes(X)).true?.should_not be_true
|
295
|
-
none(:jane.likes(X)).true?.should_not be_true
|
296
|
-
none(:jeff.likes(X)).true?.should_not be_true
|
297
|
-
none(:todd.likes(X)).true?.should_not be_true
|
298
|
-
none(:jim.likes(X)).true?.should be_true
|
299
|
-
end
|
300
229
|
|
301
|
-
it "does not hijack variables" do
|
302
|
-
A.is(X.is(5)).and(A.all{X<10}).true?.should == true
|
303
|
-
end
|
304
230
|
|
305
|
-
|
306
|
-
|
307
|
-
:john.likes(X).
|
308
|
-
:john.likes(X).
|
309
|
-
:john.likes(X).
|
310
|
-
:john.likes(X).every(:todd.likes(X)).true?.should_not be_true
|
311
|
-
end
|
312
|
-
|
313
|
-
specify "works like all" do
|
314
|
-
every(:john.likes(X),:john.likes(X)).true?.should be_true
|
315
|
-
every(:john.likes(X),:jane.likes(X)).true?.should be_true
|
316
|
-
every(:john.likes(X),:jeff.likes(X)).true?.should_not be_true
|
317
|
-
every(:john.likes(X),:todd.likes(X)).true?.should_not be_true
|
231
|
+
specify "all works" do
|
232
|
+
(:john.likes(X).all(:john.likes(X))).true?.should be_true
|
233
|
+
(:john.likes(X).all(:jane.likes(X))).true?.should be_true
|
234
|
+
(:john.likes(X).all(:jeff.likes(X))).true?.should_not be_true
|
235
|
+
(:john.likes(X).all(:todd.likes(X))).true?.should_not be_true
|
318
236
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
237
|
+
(:jane.likes(X).all(:john.likes(X))).true?.should_not be_true
|
238
|
+
(:jane.likes(X).all(:jane.likes(X))).true?.should be_true
|
239
|
+
(:jane.likes(X).all(:jeff.likes(X))).true?.should_not be_true
|
240
|
+
(:jane.likes(X).all(:todd.likes(X))).true?.should_not be_true
|
323
241
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
242
|
+
(:jeff.likes(X).all(:john.likes(X))).true?.should_not be_true
|
243
|
+
(:jeff.likes(X).all(:jane.likes(X))).true?.should_not be_true
|
244
|
+
(:jeff.likes(X).all(:jeff.likes(X))).true?.should be_true
|
245
|
+
(:jeff.likes(X).all(:todd.likes(X))).true?.should_not be_true
|
328
246
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
247
|
+
(:todd.likes(X).all(:john.likes(X))).true?.should_not be_true
|
248
|
+
(:todd.likes(X).all(:jane.likes(X))).true?.should be_true
|
249
|
+
(:todd.likes(X).all(:jeff.likes(X))).true?.should_not be_true
|
250
|
+
(:todd.likes(X).all(:todd.likes(X))).true?.should be_true
|
333
251
|
end
|
334
252
|
|
335
|
-
specify "works
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
253
|
+
specify "all works with procs" do
|
254
|
+
(:john.likes(X).all{:john.likes?(X)}).true?.should be_true
|
255
|
+
(:john.likes(X).all{:jane.likes?(X)}).true?.should be_true
|
256
|
+
(:john.likes(X).all{:jeff.likes?(X)}).true?.should_not be_true
|
257
|
+
(:john.likes(X).all{:todd.likes?(X)}).true?.should_not be_true
|
258
|
+
|
259
|
+
(:jane.likes(X).all{:john.likes?(X)}).true?.should_not be_true
|
260
|
+
(:jane.likes(X).all{:jane.likes?(X)}).true?.should be_true
|
261
|
+
(:jane.likes(X).all{:jeff.likes?(X)}).true?.should_not be_true
|
262
|
+
(:jane.likes(X).all{:todd.likes?(X)}).true?.should_not be_true
|
263
|
+
|
264
|
+
(:jeff.likes(X).all{:john.likes?(X)}).true?.should_not be_true
|
265
|
+
(:jeff.likes(X).all{:jane.likes?(X)}).true?.should_not be_true
|
266
|
+
(:jeff.likes(X).all{:jeff.likes?(X)}).true?.should be_true
|
267
|
+
(:jeff.likes(X).all{:todd.likes?(X)}).true?.should_not be_true
|
268
|
+
|
269
|
+
(:todd.likes(X).all{:john.likes?(X)}).true?.should_not be_true
|
270
|
+
(:todd.likes(X).all{:jane.likes?(X)}).true?.should be_true
|
271
|
+
(:todd.likes(X).all{:jeff.likes?(X)}).true?.should_not be_true
|
272
|
+
(:todd.likes(X).all{:todd.likes?(X)}).true?.should be_true
|
273
|
+
end
|
340
274
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
275
|
+
it "can be called with global functor syntax" do
|
276
|
+
all(:john.likes(X), :jane.likes(X)).true?.should be_true
|
277
|
+
all(:jane.likes(X), :john.likes(X)).true?.should_not be_true
|
278
|
+
any(:jane.likes(X), :todd.likes(X)).true?.should be_true
|
279
|
+
any(:john.likes(X), :todd.likes(X)).true?.should_not be_true
|
280
|
+
end
|
345
281
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
282
|
+
it "one, any, none can be called unarily" do
|
283
|
+
one(:john.likes(X)).true?.should_not be_true
|
284
|
+
one(:jane.likes(X)).true?.should_not be_true
|
285
|
+
one(:jeff.likes(X)).true?.should_not be_true
|
286
|
+
one(:todd.likes(X)).true?.should be_true
|
287
|
+
one(:jim.likes(X)).true?.should_not be_true
|
288
|
+
|
289
|
+
any(:john.likes(X)).true?.should be_true
|
290
|
+
any(:jane.likes(X)).true?.should be_true
|
291
|
+
any(:jeff.likes(X)).true?.should be_true
|
292
|
+
any(:todd.likes(X)).true?.should be_true
|
293
|
+
any(:jim.likes(X)).true?.should_not be_true
|
294
|
+
|
295
|
+
none(:john.likes(X)).true?.should_not be_true
|
296
|
+
none(:jane.likes(X)).true?.should_not be_true
|
297
|
+
none(:jeff.likes(X)).true?.should_not be_true
|
298
|
+
none(:todd.likes(X)).true?.should_not be_true
|
299
|
+
none(:jim.likes(X)).true?.should be_true
|
300
|
+
end
|
350
301
|
|
351
|
-
|
352
|
-
|
353
|
-
every(:todd.likes(X)){:jeff.likes?(X)}.true?.should_not be_true
|
354
|
-
every(:todd.likes(X)){:todd.likes?(X)}.true?.should be_true
|
302
|
+
it "does not hijack variables" do
|
303
|
+
A.is(X.is(5)).and(A.all{X<10}).true?.should == true
|
355
304
|
end
|
356
305
|
|
306
|
+
describe "every" do
|
307
|
+
specify "works as infix" do
|
308
|
+
:john.likes(X).every(:john.likes(X)).true?.should be_true
|
309
|
+
:john.likes(X).every(:jane.likes(X)).true?.should be_true
|
310
|
+
:john.likes(X).every(:jeff.likes(X)).true?.should_not be_true
|
311
|
+
:john.likes(X).every(:todd.likes(X)).true?.should_not be_true
|
312
|
+
end
|
313
|
+
|
314
|
+
specify "works like all" do
|
315
|
+
every(:john.likes(X),:john.likes(X)).true?.should be_true
|
316
|
+
every(:john.likes(X),:jane.likes(X)).true?.should be_true
|
317
|
+
every(:john.likes(X),:jeff.likes(X)).true?.should_not be_true
|
318
|
+
every(:john.likes(X),:todd.likes(X)).true?.should_not be_true
|
319
|
+
|
320
|
+
every(:jane.likes(X),:john.likes(X)).true?.should_not be_true
|
321
|
+
every(:jane.likes(X),:jane.likes(X)).true?.should be_true
|
322
|
+
every(:jane.likes(X),:jeff.likes(X)).true?.should_not be_true
|
323
|
+
every(:jane.likes(X),:todd.likes(X)).true?.should_not be_true
|
324
|
+
|
325
|
+
every(:jeff.likes(X),:john.likes(X)).true?.should_not be_true
|
326
|
+
every(:jeff.likes(X),:jane.likes(X)).true?.should_not be_true
|
327
|
+
every(:jeff.likes(X),:jeff.likes(X)).true?.should be_true
|
328
|
+
every(:jeff.likes(X),:todd.likes(X)).true?.should_not be_true
|
329
|
+
|
330
|
+
every(:todd.likes(X),:john.likes(X)).true?.should_not be_true
|
331
|
+
every(:todd.likes(X),:jane.likes(X)).true?.should be_true
|
332
|
+
every(:todd.likes(X),:jeff.likes(X)).true?.should_not be_true
|
333
|
+
every(:todd.likes(X),:todd.likes(X)).true?.should be_true
|
334
|
+
end
|
335
|
+
|
336
|
+
specify "works like all with procs" do
|
337
|
+
every(:john.likes(X)){:john.likes?(X)}.true?.should be_true
|
338
|
+
every(:john.likes(X)){:jane.likes?(X)}.true?.should be_true
|
339
|
+
every(:john.likes(X)){:jeff.likes?(X)}.true?.should_not be_true
|
340
|
+
every(:john.likes(X)){:todd.likes?(X)}.true?.should_not be_true
|
341
|
+
|
342
|
+
every(:jane.likes(X)){:john.likes?(X)}.true?.should_not be_true
|
343
|
+
every(:jane.likes(X)){:jane.likes?(X)}.true?.should be_true
|
344
|
+
every(:jane.likes(X)){:jeff.likes?(X)}.true?.should_not be_true
|
345
|
+
every(:jane.likes(X)){:todd.likes?(X)}.true?.should_not be_true
|
346
|
+
|
347
|
+
every(:jeff.likes(X)){:john.likes?(X)}.true?.should_not be_true
|
348
|
+
every(:jeff.likes(X)){:jane.likes?(X)}.true?.should_not be_true
|
349
|
+
every(:jeff.likes(X)){:jeff.likes?(X)}.true?.should be_true
|
350
|
+
every(:jeff.likes(X)){:todd.likes?(X)}.true?.should_not be_true
|
351
|
+
|
352
|
+
every(:todd.likes(X)){:john.likes?(X)}.true?.should_not be_true
|
353
|
+
every(:todd.likes(X)){:jane.likes?(X)}.true?.should be_true
|
354
|
+
every(:todd.likes(X)){:jeff.likes?(X)}.true?.should_not be_true
|
355
|
+
every(:todd.likes(X)){:todd.likes?(X)}.true?.should be_true
|
356
|
+
end
|
357
|
+
|
358
|
+
|
359
|
+
specify "can be used for assumptions" do
|
360
|
+
predicate_for Symbol, ".good"
|
361
|
+
# assumptions reverse the order
|
362
|
+
every(:john.likes(X), X.good.assumed).and(Y.good).map{Y}.should == [:beer, :water]
|
363
|
+
end
|
364
|
+
|
365
|
+
specify "passes variables" do
|
366
|
+
solve N.is(5).and K.in{1..N}.every {N.should eql 5}
|
367
|
+
end
|
368
|
+
|
369
|
+
specify "passes variables" do
|
370
|
+
solve N.is(5).and K.in{1..N}.every L.in{1..N}
|
371
|
+
end
|
372
|
+
|
373
|
+
specify "passes variables if b contains the variable" do
|
374
|
+
solve N.is(5).and every I.in{2..N}, K.is{N/I}
|
375
|
+
end
|
357
376
|
|
358
|
-
specify "can be used for assumptions" do
|
359
|
-
predicate_for Symbol, ".good"
|
360
|
-
# assumptions reverse the order
|
361
|
-
every(:john.likes(X), X.good.assumed).and(Y.good).map{Y}.should == [:beer, :water]
|
362
377
|
end
|
363
378
|
|
364
|
-
specify "passes variables" do
|
365
|
-
solve N.is(5).and K.in{1..N}.every {N.should eql 5}
|
366
|
-
end
|
367
|
-
|
368
|
-
specify "passes variables" do
|
369
|
-
solve N.is(5).and K.in{1..N}.every L.in{1..N}
|
370
|
-
end
|
371
379
|
|
372
|
-
specify "passes variables if b contains the variable" do
|
373
|
-
solve N.is(5).and every I.in{2..N}, K.is{N/I}
|
374
|
-
end
|
375
380
|
|
376
381
|
end
|
377
382
|
|
378
|
-
|
379
|
-
|
380
383
|
end
|
381
|
-
|
382
384
|
end
|