rubylog 2.0.1 → 2.1.0
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.
- 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,35 +1,37 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
describe
|
3
|
+
module RubylogSpec
|
4
|
+
describe Rubylog::ContextModules::Predicates, :rubylog=>true do
|
5
|
+
describe "#predicate_for" do
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
specify "can accept humanized predicate" do
|
8
|
+
predicate_for String, ".long"
|
9
|
+
L.long.if { L.length > 10 }
|
10
|
+
"0123456789".should_not be_long
|
11
|
+
"01234567890".should be_long
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
14
|
+
specify "can accept space-separated predicates" do
|
15
|
+
predicate_for String, ".long .short"
|
16
|
+
L.long.if { L.length > 10 }
|
17
|
+
L.short.unless L.long
|
18
|
+
"01234567890".should_not be_short
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "can accept list of predicates" do
|
22
|
+
predicate_for String, ".long", ".short"
|
23
|
+
L.long.if { L.length > 10 }
|
24
|
+
L.short.unless L.long
|
25
|
+
"01234567890".should_not be_short
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
specify "can accept array of predicates" do
|
29
|
+
predicate_for String, %w".long .short"
|
30
|
+
L.long.if { L.length > 10 }
|
31
|
+
L.short.unless L.long
|
32
|
+
"01234567890".should_not be_short
|
33
|
+
end
|
32
34
|
end
|
33
|
-
end
|
34
35
|
|
36
|
+
end
|
35
37
|
end
|
@@ -1,94 +1,96 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
require "rubylog/builtins/file_system"
|
3
3
|
|
4
|
-
|
5
|
-
describe "
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module RubylogSpec
|
5
|
+
describe "thats", :rubylog=>true do
|
6
|
+
describe "one level" do
|
7
|
+
check 4.is(ANY[Integer,thats < 10])
|
8
|
+
check 4.is(ANY[Integer,thats < 5])
|
9
|
+
check 4.is(ANY[Integer,thats < 4]).false
|
10
|
+
check 4.is(ANY[Integer,thats < 2]).false
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
describe "question mark" do
|
14
|
+
check "".is(ANY[thats.empty?])
|
15
|
+
check "a".is(ANY[thats.empty?]).false
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
describe "two levels" do
|
19
|
+
check "hello".is(ANYTHING[thats.reverse == "olleh"])
|
20
|
+
check "hello".is(ANYTHING[thats.reverse == "olle"]).false
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
describe "four levels" do
|
24
|
+
check "hello".is(ANY[thats.upcase.partition("E")[0] == "H"])
|
25
|
+
check "hello".is(ANY[thats.upcase.partition("E")[1] == "E"])
|
26
|
+
check "hello".is(ANY[thats.upcase.partition("E")[2] == "LLO"])
|
27
|
+
check "hello".is(ANY[thats.upcase.partition("E")[1] == "H"]).false
|
28
|
+
check "hello".is(ANY[thats.upcase.partition("E")[0] == "h"]).false
|
29
|
+
check "hello".is(ANY[thats.upcase.partition("L")[0] == "H"]).false
|
30
|
+
check "hello".is(ANY[thats.upcase.partition("e")[0] == "H"]).false
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
describe "files" do
|
34
|
+
check { "#{S[String, thats.start_with?(".")]}".filename_in(".").map{S}.include? ".gitignore" }
|
35
|
+
check { not "#{S[String, thats.start_with?(".")]}". dirname_in(".").map{S}.include? "lib" }
|
36
|
+
specify { "#{S[/\A(.*)\.rb/]}".filename_in("lib").map{S}.should == ["rubylog.rb"] }
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
describe "factorial" do
|
40
|
+
predicate_for Integer, ".factorial()"
|
41
|
+
0.factorial! 1
|
42
|
+
K[thats > 0].factorial(N).if K0.is{K-1}.and K0.factorial(N0).and N.is{N0*K}
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "palindrome" do
|
46
|
+
predicate_for String, ".palindrome"
|
47
|
+
S[String, thats.length <= 1].palindrome!
|
48
|
+
"#{A[thats.length == 1]}#{B}#{A}".palindrome.if B.palindrome
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
50
|
+
check "a".palindrome
|
51
|
+
check "aa".palindrome
|
52
|
+
check "aga".palindrome
|
53
|
+
check "aaa".palindrome
|
54
|
+
check "avava".palindrome
|
55
|
+
check "ab".palindrome.false
|
56
|
+
check "abb".palindrome.false
|
57
|
+
check "abab".palindrome.false
|
58
|
+
end
|
48
59
|
|
49
|
-
check "a".palindrome
|
50
|
-
check "aa".palindrome
|
51
|
-
check "aga".palindrome
|
52
|
-
check "aaa".palindrome
|
53
|
-
check "avava".palindrome
|
54
|
-
check "ab".palindrome.false
|
55
|
-
check "abb".palindrome.false
|
56
|
-
check "abab".palindrome.false
|
57
60
|
end
|
58
61
|
|
59
|
-
|
62
|
+
describe "thats_not", :rubylog=>true do
|
63
|
+
describe "one level" do
|
64
|
+
check 4.is(ANY[Integer,thats_not < 10]).false
|
65
|
+
check 4.is(ANY[Integer,thats_not < 5]).false
|
66
|
+
check 4.is(ANY[Integer,thats_not < 4])
|
67
|
+
check 4.is(ANY[Integer,thats_not < 2])
|
68
|
+
end
|
60
69
|
|
61
|
-
describe "
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
check 4.is(ANY[Integer,thats_not < 4])
|
66
|
-
check 4.is(ANY[Integer,thats_not < 2])
|
67
|
-
end
|
70
|
+
describe "question mark" do
|
71
|
+
check "".is(ANY[thats_not.empty?]).false
|
72
|
+
check "a".is(ANY[thats_not.empty?])
|
73
|
+
end
|
68
74
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
75
|
+
describe "two levels" do
|
76
|
+
check "hello".is(ANYTHING[thats_not.reverse == "olleh"]).false
|
77
|
+
check "hello".is(ANYTHING[thats_not.reverse == "olle"])
|
78
|
+
end
|
73
79
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
80
|
+
describe "four levels" do
|
81
|
+
check "hello".is(ANY[thats_not.upcase.partition("E")[0] == "H"]).false
|
82
|
+
check "hello".is(ANY[thats_not.upcase.partition("E")[1] == "E"]).false
|
83
|
+
check "hello".is(ANY[thats_not.upcase.partition("E")[2] == "LLO"]).false
|
84
|
+
check "hello".is(ANY[thats_not.upcase.partition("E")[1] == "H"])
|
85
|
+
check "hello".is(ANY[thats_not.upcase.partition("E")[0] == "h"])
|
86
|
+
check "hello".is(ANY[thats_not.upcase.partition("L")[0] == "H"])
|
87
|
+
check "hello".is(ANY[thats_not.upcase.partition("e")[0] == "H"])
|
88
|
+
end
|
78
89
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
check "hello".is(ANY[thats_not.upcase.partition("E")[1] == "H"])
|
84
|
-
check "hello".is(ANY[thats_not.upcase.partition("E")[0] == "h"])
|
85
|
-
check "hello".is(ANY[thats_not.upcase.partition("L")[0] == "H"])
|
86
|
-
check "hello".is(ANY[thats_not.upcase.partition("e")[0] == "H"])
|
87
|
-
end
|
90
|
+
describe "files" do
|
91
|
+
check { not "#{S[String, thats_not.start_with?(".")]}".filename_in(".").map{S}.include? ".gitignore" }
|
92
|
+
check { "#{S[String, thats_not.start_with?(".")]}". dirname_in(".").map{S}.include? "lib" }
|
93
|
+
end
|
88
94
|
|
89
|
-
describe "files" do
|
90
|
-
check { not "#{S[String, thats_not.start_with?(".")]}".filename_in(".").map{S}.include? ".gitignore" }
|
91
|
-
check { "#{S[String, thats_not.start_with?(".")]}". dirname_in(".").map{S}.include? "lib" }
|
92
95
|
end
|
93
|
-
|
94
96
|
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
3
|
+
module RubylogSpec
|
4
|
+
describe Rubylog::DSL::ArraySplat, :rubylog=>true do
|
5
|
+
describe "#inspect" do
|
6
|
+
[*A].inspect.should == "[*A]"
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
specify "#==" do
|
10
|
+
[*A].should == [*A]
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
specify "#eql?" do
|
14
|
+
[*A].should eql [*A]
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
@@ -1,26 +1,28 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module RubylogSpec
|
4
|
+
describe Rubylog::DSL::Indicators do
|
5
|
+
describe "#humanize_indicator" do
|
6
|
+
specify { Rubylog::DSL::Indicators.humanize_indicator([:fail,0]).should == ":fail" }
|
7
|
+
specify { Rubylog::DSL::Indicators.humanize_indicator([:false,1]).should == ".false" }
|
8
|
+
specify { Rubylog::DSL::Indicators.humanize_indicator([:and,2]).should == ".and()" }
|
9
|
+
specify { Rubylog::DSL::Indicators.humanize_indicator([:splits,3]).should == ".splits(,)" }
|
10
|
+
specify { Rubylog::DSL::Indicators.humanize_indicator([:is,4]).should == ".is(,,)" }
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
describe "#unhumanize_indicator" do
|
14
|
+
specify { Rubylog::DSL::Indicators.unhumanize_indicator(":fail" ).should == [:fail,0] }
|
15
|
+
specify { Rubylog::DSL::Indicators.unhumanize_indicator(".false" ).should == [:false,1] }
|
16
|
+
specify { Rubylog::DSL::Indicators.unhumanize_indicator(".and()" ).should == [:and,2] }
|
17
|
+
specify { Rubylog::DSL::Indicators.unhumanize_indicator(".splits(,)" ).should == [:splits,3] }
|
18
|
+
specify { Rubylog::DSL::Indicators.unhumanize_indicator(".is(,,)" ).should == [:is,4] }
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
describe "with comment variables" do
|
21
|
+
specify { Rubylog::DSL::Indicators.unhumanize_indicator("Predicate.false" ).should == [:false,1] }
|
22
|
+
specify { Rubylog::DSL::Indicators.unhumanize_indicator("a.and(b)" ).should == [:and,2] }
|
23
|
+
specify { Rubylog::DSL::Indicators.unhumanize_indicator("LIST.splits(HEAD,TAIL)" ).should == [:splits,3] }
|
24
|
+
specify { Rubylog::DSL::Indicators.unhumanize_indicator("C.is(A,OP,B)" ).should == [:is,4] }
|
25
|
+
end
|
24
26
|
end
|
25
|
-
end
|
26
|
-
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,43 +1,45 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module RubylogSpec
|
4
|
+
describe Rubylog::DSL::Primitives, :rubylog=>true do
|
5
|
+
describe "#primitives" do
|
6
|
+
before do
|
7
|
+
String.instance_methods.should_not include :looong
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
it "defines functors on default subject" do
|
11
|
+
self.default_subject = String
|
12
|
+
class << primitives
|
13
|
+
def looong s
|
14
|
+
end
|
13
15
|
end
|
16
|
+
String.instance_methods.should include :looong
|
17
|
+
String.instance_methods.should include :looong!
|
18
|
+
String.instance_methods.should include :looong?
|
14
19
|
end
|
15
|
-
String.instance_methods.should include :looong
|
16
|
-
String.instance_methods.should include :looong!
|
17
|
-
String.instance_methods.should include :looong?
|
18
20
|
end
|
19
|
-
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
describe "#primitives_for" do
|
23
|
+
before do
|
24
|
+
Integer.instance_methods.should_not include :large
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
it "defines functors on the given subject" do
|
28
|
+
class << primitives_for(Integer)
|
29
|
+
def large s
|
30
|
+
end
|
29
31
|
end
|
32
|
+
Integer.instance_methods.should include :large
|
33
|
+
Integer.instance_methods.should include :large!
|
34
|
+
Integer.instance_methods.should include :large?
|
30
35
|
end
|
31
|
-
Integer.instance_methods.should include :large
|
32
|
-
Integer.instance_methods.should include :large!
|
33
|
-
Integer.instance_methods.should include :large?
|
34
36
|
end
|
35
|
-
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
describe "Primitives#inspect" do
|
39
|
+
specify do
|
40
|
+
primitives_for(Integer).inspect.should =~ /\Aprimitives_for\(.*\)\z/
|
41
|
+
end
|
40
42
|
end
|
41
|
-
end
|
42
43
|
|
44
|
+
end
|
43
45
|
end
|
data/spec/rubylog/errors_spec.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
module RubylogSpec
|
4
|
+
describe "Rubylog errors", :rubylog=>true do
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
describe "syntax error" do
|
7
|
+
predicate_for String, ".happy"
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
specify { proc{ "John".happy.if }.should raise_error Rubylog::SyntaxError }
|
10
|
+
specify { proc{ "John".happy.if! }.should raise_error Rubylog::SyntaxError }
|
11
|
+
specify { proc{ "John".happy.unless }.should raise_error Rubylog::SyntaxError }
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
describe Rubylog::InstantiationError do
|
15
|
+
specify { proc { A.true? }.should raise_error(Rubylog::InstantiationError, "Instantiation error in A") }
|
16
|
+
specify { proc { A.sum_of(B,1).true? }.should raise_error(Rubylog::InstantiationError, "Instantiation error in A.sum_of(B, 1)") }
|
17
|
+
end
|
17
18
|
|
19
|
+
end
|
18
20
|
end
|
@@ -1,83 +1,85 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module RubylogSpec
|
4
|
+
describe "unification", :rubylog=>true do
|
5
|
+
predicate_for Symbol, ".likes"
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
7
|
+
it "works for variables" do
|
8
|
+
result = false
|
9
|
+
A.rubylog_unify(12) { result = true }
|
10
|
+
result.should == true
|
11
|
+
end
|
12
|
+
it "works for used classes" do
|
13
|
+
result = false
|
14
|
+
:john.rubylog_unify(A) { result = true }
|
15
|
+
result.should == true
|
16
|
+
end
|
17
|
+
it "works for constants" do
|
18
|
+
result = false
|
19
|
+
:john.rubylog_unify(:john) { result = true }
|
20
|
+
result.should == true
|
21
|
+
end
|
22
|
+
it "fails for different constants" do
|
23
|
+
result = false
|
24
|
+
:john.rubylog_unify(:mary) { result = true }
|
25
|
+
result.should == false
|
26
|
+
end
|
27
|
+
it "works on structures" do
|
28
|
+
result = false
|
29
|
+
(:john.likes :beer).rubylog_unify(A.likes B) { result = true }
|
30
|
+
result.should == true
|
31
|
+
end
|
32
|
+
it "works on structures with equal values" do
|
33
|
+
result = false
|
34
|
+
(:john.likes :beer).rubylog_unify(:john.likes :beer) { result = true }
|
35
|
+
result.should == true
|
36
|
+
end
|
37
|
+
it "works on structures with different values" do
|
38
|
+
result = false
|
39
|
+
(:john.likes :beer).rubylog_unify(:john.likes :milk) { result = true }
|
40
|
+
result.should == false
|
41
|
+
end
|
42
|
+
it "works on structures with variables and equal values" do
|
43
|
+
result = false
|
44
|
+
(:john.likes :beer).rubylog_unify(X.likes :beer) { result = true }
|
45
|
+
result.should == true
|
46
|
+
end
|
47
|
+
it "works on structures with variables and equal values #2" do
|
48
|
+
result = false
|
49
|
+
(:john.likes :beer).rubylog_unify(:john.likes DRINK) { result = true }
|
50
|
+
result.should == true
|
51
|
+
end
|
52
|
+
it "works on structures with variables and different values" do
|
53
|
+
result = false
|
54
|
+
(:john.likes :beer).rubylog_unify(X.likes :milk) { result = true }
|
55
|
+
result.should == false
|
56
|
+
end
|
57
|
+
it "works on structures with variables and different values #2" do
|
58
|
+
result = false
|
59
|
+
(:john.likes :beer).rubylog_unify(:jane.likes D) { result = true }
|
60
|
+
result.should == false
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
63
|
+
it "works on structures with repeated variables #1" do
|
64
|
+
result = false
|
65
|
+
(A.likes A).rubylog_match_variables.rubylog_unify(:john.likes :jane) { result = true }
|
66
|
+
result.should == false
|
67
|
+
(A.likes A).rubylog_match_variables.rubylog_unify(:john.likes :john) { result = true }
|
68
|
+
result.should == true
|
69
|
+
end
|
70
|
+
it "works on structures with repeated variables #1" do
|
71
|
+
result = false
|
72
|
+
(:john.likes :jane).rubylog_unify(A.likes(A).rubylog_match_variables) { result = true }
|
73
|
+
result.should == false
|
74
|
+
(:john.likes :john).rubylog_unify(A.likes(A).rubylog_match_variables) { result = true }
|
75
|
+
result.should == true
|
76
|
+
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
it "works for second-order variables" do
|
79
|
+
result = false
|
80
|
+
(:john.likes :beer).rubylog_unify(A) { result = true }
|
81
|
+
result.should == true
|
82
|
+
end
|
82
83
|
|
84
|
+
end
|
83
85
|
end
|