rubylog 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/Gemfile +2 -0
  2. data/Gemfile.lock +10 -0
  3. data/README.rdoc +1 -1
  4. data/RELEASE_NOTES.rdoc +7 -4
  5. data/VERSION +1 -1
  6. data/{examples → benchmark}/benchmark.rb +1 -0
  7. data/{examples → benchmark}/benchmark/compiled_not_indexed.rb +0 -0
  8. data/{examples → benchmark}/benchmark/compiled_sequence_indexed.rb +0 -0
  9. data/{examples → benchmark}/benchmark/indexed_procedure.rb +0 -0
  10. data/{examples → benchmark}/benchmark/prolog.rb +0 -0
  11. data/benchmark/benchmark/pure.rb +28 -0
  12. data/bin/rubylog +14 -0
  13. data/examples/a_plus_b.rb +2 -2
  14. data/examples/dcg.rb +22 -26
  15. data/examples/dcg2.rb +25 -30
  16. data/examples/divisors.rb +1 -3
  17. data/examples/factorial.rb +8 -15
  18. data/examples/file_search.rb +14 -13
  19. data/examples/hanoi.rb +1 -3
  20. data/examples/hu/csaladfa.rb +0 -4
  21. data/examples/n_queens.rb +17 -22
  22. data/examples/palindrome_detection.rb +1 -2
  23. data/examples/parsing.rb +19 -23
  24. data/examples/permutation.rb +1 -3
  25. data/examples/primality_by_division.rb +2 -2
  26. data/examples/sieve_of_eratosthenes.rb +2 -2
  27. data/examples/string_interpolation.rb +0 -3
  28. data/examples/tracing.rb +0 -4
  29. data/lib/rubylog/builtins/assumption.rb +2 -1
  30. data/lib/rubylog/builtins/file_system.rb +1 -1
  31. data/lib/rubylog/default_context.rb +3 -5
  32. data/lib/rubylog/mixins/kernel.rb +9 -1
  33. data/lib/rubylog/rubylog_files.rb +7 -0
  34. data/rubylog.gemspec +17 -22
  35. data/spec/inriasuite_spec.rb +851 -847
  36. data/spec/integration/dsl_spec.rb +32 -29
  37. data/spec/rspec/rubylog_spec.rb +46 -52
  38. data/spec/rubylog/assertable_spec.rb +92 -90
  39. data/spec/rubylog/builtins/arithmetics_spec.rb +92 -90
  40. data/spec/rubylog/builtins/assumption_spec.rb +59 -57
  41. data/spec/rubylog/builtins/ensure_spec.rb +6 -4
  42. data/spec/rubylog/builtins/file_system_spec.rb +41 -39
  43. data/spec/rubylog/builtins/logic_spec.rb +308 -306
  44. data/spec/rubylog/builtins/reflection_spec.rb +31 -29
  45. data/spec/rubylog/builtins/term_spec.rb +62 -60
  46. data/spec/rubylog/context_modules/demonstration_spec.rb +108 -106
  47. data/spec/rubylog/context_modules/predicates_spec.rb +29 -27
  48. data/spec/rubylog/context_modules/thats_spec.rb +77 -75
  49. data/spec/rubylog/dsl/array_splat_spec.rb +11 -9
  50. data/spec/rubylog/dsl/indicators_spec.rb +23 -21
  51. data/spec/rubylog/dsl/primitives_spec.rb +30 -28
  52. data/spec/rubylog/errors_spec.rb +13 -11
  53. data/spec/rubylog/interfaces/term_spec.rb +78 -76
  54. data/spec/rubylog/mixins/array_spec.rb +60 -58
  55. data/spec/rubylog/mixins/composite_term_spec.rb +55 -53
  56. data/spec/rubylog/mixins/proc_spec.rb +48 -46
  57. data/spec/rubylog/mixins/string_spec.rb +45 -43
  58. data/spec/rubylog/mixins/symbol_spec.rb +7 -5
  59. data/spec/rubylog/procedure_spec.rb +8 -6
  60. data/spec/rubylog/rule_spec.rb +10 -8
  61. data/spec/rubylog/structure_spec.rb +73 -71
  62. data/spec/rubylog/term_spec.rb +5 -3
  63. data/spec/rubylog/tracing_spec.rb +35 -33
  64. data/spec/rubylog/variable_spec.rb +249 -247
  65. data/spec/spec_helper.rb +4 -0
  66. metadata +54 -43
  67. data/examples/benchmark/pure.rb +0 -26
  68. data/examples/checkmate.rb +0 -88
  69. data/examples/combination.rb +0 -17
  70. data/examples/directory_structure_logic.rb +0 -17
  71. data/examples/dirlist.rb +0 -4
  72. data/examples/enumerators.rb +0 -30
  73. data/examples/hello.rb +0 -17
  74. data/examples/mice.rb +0 -92
  75. data/examples/mice2.rb +0 -37
  76. data/examples/object_oriented.rb +0 -14
  77. data/examples/prefix.rb +0 -13
  78. data/examples/primitives.rb +0 -26
  79. data/examples/sudoku.rb +0 -17
  80. data/spec/integration/theory_as_module_spec.rb +0 -20
  81. data/spec/integration/theory_as_module_with_include_spec.rb +0 -14
@@ -1,35 +1,37 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Rubylog::ContextModules::Predicates, :rubylog=>true do
4
- describe "#predicate_for" do
3
+ module RubylogSpec
4
+ describe Rubylog::ContextModules::Predicates, :rubylog=>true do
5
+ describe "#predicate_for" do
5
6
 
6
- specify "can accept humanized predicate" do
7
- predicate_for String, ".long"
8
- L.long.if { L.length > 10 }
9
- "0123456789".should_not be_long
10
- "01234567890".should be_long
11
- end
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
- specify "can accept space-separated predicates" do
14
- predicate_for String, ".long .short"
15
- L.long.if { L.length > 10 }
16
- L.short.unless L.long
17
- "01234567890".should_not be_short
18
- end
19
-
20
- specify "can accept list of predicates" do
21
- predicate_for String, ".long", ".short"
22
- L.long.if { L.length > 10 }
23
- L.short.unless L.long
24
- "01234567890".should_not be_short
25
- end
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
- specify "can accept array of predicates" do
28
- predicate_for String, %w".long .short"
29
- L.long.if { L.length > 10 }
30
- L.short.unless L.long
31
- "01234567890".should_not be_short
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
- describe "thats", :rubylog=>true do
5
- describe "one level" do
6
- check 4.is(ANY[Integer,thats < 10])
7
- check 4.is(ANY[Integer,thats < 5])
8
- check 4.is(ANY[Integer,thats < 4]).false
9
- check 4.is(ANY[Integer,thats < 2]).false
10
- end
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
- describe "question mark" do
13
- check "".is(ANY[thats.empty?])
14
- check "a".is(ANY[thats.empty?]).false
15
- end
13
+ describe "question mark" do
14
+ check "".is(ANY[thats.empty?])
15
+ check "a".is(ANY[thats.empty?]).false
16
+ end
16
17
 
17
- describe "two levels" do
18
- check "hello".is(ANYTHING[thats.reverse == "olleh"])
19
- check "hello".is(ANYTHING[thats.reverse == "olle"]).false
20
- end
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
- describe "four levels" do
23
- check "hello".is(ANY[thats.upcase.partition("E")[0] == "H"])
24
- check "hello".is(ANY[thats.upcase.partition("E")[1] == "E"])
25
- check "hello".is(ANY[thats.upcase.partition("E")[2] == "LLO"])
26
- check "hello".is(ANY[thats.upcase.partition("E")[1] == "H"]).false
27
- check "hello".is(ANY[thats.upcase.partition("E")[0] == "h"]).false
28
- check "hello".is(ANY[thats.upcase.partition("L")[0] == "H"]).false
29
- check "hello".is(ANY[thats.upcase.partition("e")[0] == "H"]).false
30
- end
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
- describe "files" do
33
- check { "#{S[String, thats.start_with?(".")]}".filename_in(".").map{S}.include? ".gitignore" }
34
- check { not "#{S[String, thats.start_with?(".")]}". dirname_in(".").map{S}.include? "lib" }
35
- specify { "#{S[/\A(.*)\.rb/]}".filename_in("lib").map{S}.should == ["rubylog.rb"] }
36
- end
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
- describe "factorial" do
39
- predicate_for Integer, ".factorial()"
40
- 0.factorial! 1
41
- K[thats > 0].factorial(N).if K0.is{K-1}.and K0.factorial(N0).and N.is{N0*K}
42
- end
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
- describe "palindrome" do
45
- predicate_for String, ".palindrome"
46
- S[String, thats.length <= 1].palindrome!
47
- "#{A[thats.length == 1]}#{B}#{A}".palindrome.if B.palindrome
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
- end
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 "thats_not", :rubylog=>true do
62
- describe "one level" do
63
- check 4.is(ANY[Integer,thats_not < 10]).false
64
- check 4.is(ANY[Integer,thats_not < 5]).false
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
- describe "question mark" do
70
- check "".is(ANY[thats_not.empty?]).false
71
- check "a".is(ANY[thats_not.empty?])
72
- end
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
- describe "two levels" do
75
- check "hello".is(ANYTHING[thats_not.reverse == "olleh"]).false
76
- check "hello".is(ANYTHING[thats_not.reverse == "olle"])
77
- end
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
- describe "four levels" do
80
- check "hello".is(ANY[thats_not.upcase.partition("E")[0] == "H"]).false
81
- check "hello".is(ANY[thats_not.upcase.partition("E")[1] == "E"]).false
82
- check "hello".is(ANY[thats_not.upcase.partition("E")[2] == "LLO"]).false
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
- describe Rubylog::DSL::ArraySplat, :rubylog=>true do
4
- describe "#inspect" do
5
- [*A].inspect.should == "[*A]"
6
- end
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
- specify "#==" do
9
- [*A].should == [*A]
10
- end
9
+ specify "#==" do
10
+ [*A].should == [*A]
11
+ end
11
12
 
12
- specify "#eql?" do
13
- [*A].should eql [*A]
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
- describe Rubylog::DSL::Indicators do
4
- describe "#humanize_indicator" do
5
- specify { Rubylog::DSL::Indicators.humanize_indicator([:fail,0]).should == ":fail" }
6
- specify { Rubylog::DSL::Indicators.humanize_indicator([:false,1]).should == ".false" }
7
- specify { Rubylog::DSL::Indicators.humanize_indicator([:and,2]).should == ".and()" }
8
- specify { Rubylog::DSL::Indicators.humanize_indicator([:splits,3]).should == ".splits(,)" }
9
- specify { Rubylog::DSL::Indicators.humanize_indicator([:is,4]).should == ".is(,,)" }
10
- end
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
- describe "#unhumanize_indicator" do
13
- specify { Rubylog::DSL::Indicators.unhumanize_indicator(":fail" ).should == [:fail,0] }
14
- specify { Rubylog::DSL::Indicators.unhumanize_indicator(".false" ).should == [:false,1] }
15
- specify { Rubylog::DSL::Indicators.unhumanize_indicator(".and()" ).should == [:and,2] }
16
- specify { Rubylog::DSL::Indicators.unhumanize_indicator(".splits(,)" ).should == [:splits,3] }
17
- specify { Rubylog::DSL::Indicators.unhumanize_indicator(".is(,,)" ).should == [:is,4] }
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
- describe "with comment variables" do
20
- specify { Rubylog::DSL::Indicators.unhumanize_indicator("Predicate.false" ).should == [:false,1] }
21
- specify { Rubylog::DSL::Indicators.unhumanize_indicator("a.and(b)" ).should == [:and,2] }
22
- specify { Rubylog::DSL::Indicators.unhumanize_indicator("LIST.splits(HEAD,TAIL)" ).should == [:splits,3] }
23
- specify { Rubylog::DSL::Indicators.unhumanize_indicator("C.is(A,OP,B)" ).should == [:is,4] }
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
- describe Rubylog::DSL::Primitives, :rubylog=>true do
4
- describe "#primitives" do
5
- before do
6
- String.instance_methods.should_not include :looong
7
- end
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
- it "defines functors on default subject" do
10
- self.default_subject = String
11
- class << primitives
12
- def looong s
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
- describe "#primitives_for" do
22
- before do
23
- Integer.instance_methods.should_not include :large
24
- end
22
+ describe "#primitives_for" do
23
+ before do
24
+ Integer.instance_methods.should_not include :large
25
+ end
25
26
 
26
- it "defines functors on the given subject" do
27
- class << primitives_for(Integer)
28
- def large s
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
- describe "Primitives#inspect" do
38
- specify do
39
- primitives_for(Integer).inspect.should =~ /\Aprimitives_for\(.*\)\z/
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
@@ -1,18 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Rubylog errors", :rubylog=>true do
3
+ module RubylogSpec
4
+ describe "Rubylog errors", :rubylog=>true do
4
5
 
5
- describe "syntax error" do
6
- predicate_for String, ".happy"
6
+ describe "syntax error" do
7
+ predicate_for String, ".happy"
7
8
 
8
- specify { proc{ "John".happy.if }.should raise_error Rubylog::SyntaxError }
9
- specify { proc{ "John".happy.if! }.should raise_error Rubylog::SyntaxError }
10
- specify { proc{ "John".happy.unless }.should raise_error Rubylog::SyntaxError }
11
- end
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
- describe Rubylog::InstantiationError do
14
- specify { proc { A.true? }.should raise_error(Rubylog::InstantiationError, "Instantiation error in A") }
15
- specify { proc { A.sum_of(B,1).true? }.should raise_error(Rubylog::InstantiationError, "Instantiation error in A.sum_of(B, 1)") }
16
- end
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
- describe "unification", :rubylog=>true do
4
- predicate_for Symbol, ".likes"
3
+ module RubylogSpec
4
+ describe "unification", :rubylog=>true do
5
+ predicate_for Symbol, ".likes"
5
6
 
6
- it "works for variables" do
7
- result = false
8
- A.rubylog_unify(12) { result = true }
9
- result.should == true
10
- end
11
- it "works for used classes" do
12
- result = false
13
- :john.rubylog_unify(A) { result = true }
14
- result.should == true
15
- end
16
- it "works for constants" do
17
- result = false
18
- :john.rubylog_unify(:john) { result = true }
19
- result.should == true
20
- end
21
- it "fails for different constants" do
22
- result = false
23
- :john.rubylog_unify(:mary) { result = true }
24
- result.should == false
25
- end
26
- it "works on structures" do
27
- result = false
28
- (:john.likes :beer).rubylog_unify(A.likes B) { result = true }
29
- result.should == true
30
- end
31
- it "works on structures with equal values" do
32
- result = false
33
- (:john.likes :beer).rubylog_unify(:john.likes :beer) { result = true }
34
- result.should == true
35
- end
36
- it "works on structures with different values" do
37
- result = false
38
- (:john.likes :beer).rubylog_unify(:john.likes :milk) { result = true }
39
- result.should == false
40
- end
41
- it "works on structures with variables and equal values" do
42
- result = false
43
- (:john.likes :beer).rubylog_unify(X.likes :beer) { result = true }
44
- result.should == true
45
- end
46
- it "works on structures with variables and equal values #2" do
47
- result = false
48
- (:john.likes :beer).rubylog_unify(:john.likes DRINK) { result = true }
49
- result.should == true
50
- end
51
- it "works on structures with variables and different values" do
52
- result = false
53
- (:john.likes :beer).rubylog_unify(X.likes :milk) { result = true }
54
- result.should == false
55
- end
56
- it "works on structures with variables and different values #2" do
57
- result = false
58
- (:john.likes :beer).rubylog_unify(:jane.likes D) { result = true }
59
- result.should == false
60
- end
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
- it "works on structures with repeated variables #1" do
63
- result = false
64
- (A.likes A).rubylog_match_variables.rubylog_unify(:john.likes :jane) { result = true }
65
- result.should == false
66
- (A.likes A).rubylog_match_variables.rubylog_unify(:john.likes :john) { result = true }
67
- result.should == true
68
- end
69
- it "works on structures with repeated variables #1" do
70
- result = false
71
- (:john.likes :jane).rubylog_unify(A.likes(A).rubylog_match_variables) { result = true }
72
- result.should == false
73
- (:john.likes :john).rubylog_unify(A.likes(A).rubylog_match_variables) { result = true }
74
- result.should == true
75
- end
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
- it "works for second-order variables" do
78
- result = false
79
- (:john.likes :beer).rubylog_unify(A) { result = true }
80
- result.should == true
81
- end
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