yargi 0.1.2 → 0.2.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.
Files changed (54) hide show
  1. data/CHANGELOG.md +54 -0
  2. data/Gemfile +7 -0
  3. data/Gemfile.lock +23 -0
  4. data/LICENCE.md +22 -0
  5. data/Manifest.txt +15 -0
  6. data/README.md +128 -0
  7. data/Rakefile +23 -0
  8. data/examples/fs2dot.rb +1 -1
  9. data/examples/random.rb +20 -0
  10. data/lib/yargi.rb +8 -10
  11. data/lib/yargi/decorate.rb +55 -0
  12. data/lib/yargi/digraph.rb +71 -46
  13. data/lib/yargi/digraph_edge.rb +23 -23
  14. data/lib/yargi/digraph_vertex.rb +27 -27
  15. data/lib/yargi/edge_set.rb +12 -12
  16. data/lib/yargi/element_set.rb +54 -54
  17. data/lib/yargi/loader.rb +1 -0
  18. data/lib/yargi/markable.rb +12 -12
  19. data/lib/yargi/predicate.rb +62 -43
  20. data/lib/yargi/random.rb +98 -0
  21. data/lib/yargi/version.rb +14 -0
  22. data/lib/yargi/vertex_set.rb +12 -12
  23. data/spec/spec_helper.rb +2 -0
  24. data/spec/test_decorate.rb +28 -0
  25. data/spec/test_digraph.rb +42 -0
  26. data/spec/test_random.rb +45 -0
  27. data/spec/test_yargi.rb +8 -0
  28. data/tasks/debug_mail.rake +75 -0
  29. data/tasks/debug_mail.txt +13 -0
  30. data/tasks/gem.rake +68 -0
  31. data/tasks/spec_test.rake +71 -0
  32. data/tasks/unit_test.rake +76 -0
  33. data/tasks/yard.rake +51 -0
  34. data/test/test_all.rb +1 -1
  35. data/test/yargi/README-example.gif +0 -0
  36. data/test/yargi/digraph_set_features_test.rb +14 -16
  37. data/test/yargi/digraph_test.rb +33 -33
  38. data/test/yargi/digraph_vertex_test.rb +9 -9
  39. data/test/yargi/documentation_test.rb +7 -7
  40. data/test/yargi/edge_set_test.rb +3 -3
  41. data/test/yargi/element_set_test.rb +2 -2
  42. data/test/yargi/hypotheses_test.rb +4 -4
  43. data/test/yargi/markable_test.rb +11 -11
  44. data/test/yargi/predicate_test.rb +14 -14
  45. data/test/yargi/source-sink.gif +0 -0
  46. data/test/yargi/vertex_set_test.rb +7 -7
  47. data/yargi.gemspec +187 -0
  48. data/yargi.noespec +23 -0
  49. metadata +110 -38
  50. data/CONTRIBUTE +0 -11
  51. data/LICENCE +0 -25
  52. data/README +0 -79
  53. data/examples/fs2dot.dot +0 -78
  54. data/examples/fs2dot.gif +0 -0
@@ -10,7 +10,7 @@ module Yargi
10
10
  @graph.connect(@s1, @s2, {:label => 'a'})
11
11
  @graph.connect(@s2, @s1, {:label => 'b'})
12
12
  end
13
-
13
+
14
14
  def test_source=
15
15
  @graph.edges.source=@s1
16
16
  assert @graph.edges.length==2
@@ -19,7 +19,7 @@ module Yargi
19
19
  assert @s1.out_edges.length==2
20
20
  assert @s1.in_edges.length==1
21
21
  end
22
-
22
+
23
23
  def test_target=
24
24
  @graph.edges.target=@s1
25
25
  assert @graph.edges.length==2
@@ -28,6 +28,6 @@ module Yargi
28
28
  assert @s1.out_edges.length==1
29
29
  assert @s1.in_edges.length==2
30
30
  end
31
-
31
+
32
32
  end
33
33
  end
@@ -3,7 +3,7 @@ require 'yargi'
3
3
 
4
4
  module Yargi
5
5
  class ElementSetTest < Test::Unit::TestCase
6
-
6
+
7
7
  def test_flatten
8
8
  e = ElementSet[ElementSet[1, 2, 3], ElementSet[4, 5, 6]]
9
9
  assert_equal ElementSet[1, 2, 3, 4, 5, 6], e.flatten
@@ -12,6 +12,6 @@ module Yargi
12
12
  assert EdgeSet===e
13
13
  assert_equal EdgeSet[1, 2, 3, 4, 5, 6, 7], e.flatten
14
14
  end
15
-
15
+
16
16
  end
17
17
  end
@@ -1,10 +1,10 @@
1
1
  require 'test/unit'
2
2
 
3
3
  module Yargi
4
-
5
- # Checks some hypotheses that we make about Ruby
4
+
5
+ # Checks some hypotheses that we make about Ruby
6
6
  class HypothesesTest < Test::Unit::TestCase
7
-
7
+
8
8
  def test_method_missing_handles_block_as_expected
9
9
  p = Object.new
10
10
  def p.say_hello
@@ -24,7 +24,7 @@ module Yargi
24
24
  assert_equal "Hello anonymous", o.say_hello
25
25
  assert_equal "Hello blambeau", o.say_hello {"blambeau"}
26
26
  end
27
-
27
+
28
28
  end # class HypothesesTest
29
29
 
30
30
  end
@@ -3,32 +3,32 @@ require 'yargi'
3
3
 
4
4
  module Yargi
5
5
  class MarkableTest < Test::Unit::TestCase
6
-
6
+
7
7
  def setup
8
8
  @object = Object.new
9
9
  @object.extend Yargi::Markable
10
10
  end
11
-
11
+
12
12
  def test_mark_set_and_get
13
13
  @object.set_mark("hello", "world")
14
14
  assert_equal "world", @object.get_mark("hello")
15
15
  @object.set_mark("hello", "world1")
16
16
  assert_equal "world1", @object.get_mark("hello")
17
17
  end
18
-
18
+
19
19
  def test_has_mark
20
20
  @object.set_mark("hello", "world")
21
21
  assert @object.has_mark?("hello")
22
22
  assert_equal false, @object.has_mark?("hello1")
23
23
  end
24
-
24
+
25
25
  def test_mark_set_and_get_though_hash_api
26
26
  @object["hello"] = "world"
27
27
  assert_equal "world", @object["hello"]
28
28
  @object["hello"] = "world1"
29
29
  assert_equal "world1", @object["hello"]
30
30
  end
31
-
31
+
32
32
  def test_friendly_methods
33
33
  @object.set_mark(:first, 1)
34
34
  assert_equal 1, @object.first
@@ -37,7 +37,7 @@ module Yargi
37
37
  @object.first = 2
38
38
  assert_equal 2, @object.first
39
39
  end
40
-
40
+
41
41
  def test_it_is_not_intrusive
42
42
  @object[:merge_marks] = 1
43
43
  assert_nothing_raised do
@@ -46,13 +46,13 @@ module Yargi
46
46
  assert_equal 1, @object[:merge_marks]
47
47
  assert_equal "marks", @object["hello"]
48
48
  end
49
-
49
+
50
50
  def test_add_marks
51
51
  @object.add_marks(:hello => 'world', :priority => 1.0)
52
52
  assert_equal 'world', @object[:hello]
53
53
  assert_equal 1.0, @object[:priority]
54
54
  end
55
-
55
+
56
56
  def test_add_marks_with_block
57
57
  @object.add_marks do |v|
58
58
  {:hello => 'world', :priority => 1.0, :debug => v.to_s}
@@ -61,7 +61,7 @@ module Yargi
61
61
  assert_equal 1.0, @object[:priority]
62
62
  assert_not_nil @object[:debug]
63
63
  end
64
-
64
+
65
65
  def test_add_marks_with_both
66
66
  @object.add_marks(:hello => 'world') do |v|
67
67
  {:priority => 1.0, :debug => v.to_s}
@@ -70,7 +70,7 @@ module Yargi
70
70
  assert_equal 1.0, @object[:priority]
71
71
  assert_not_nil @object[:debug]
72
72
  end
73
-
73
+
74
74
  def test_to_h
75
75
  @object.set_mark(:me, "blambeau")
76
76
  @object.add_marks(:hello => "world", :who => "yarvi", :nil => nil)
@@ -81,6 +81,6 @@ module Yargi
81
81
  expected = {:me => "blambeau", :hello => "world", :who => "yarvi"}
82
82
  assert_equal expected, @object.to_h()
83
83
  end
84
-
84
+
85
85
  end
86
86
  end
@@ -2,10 +2,10 @@ require 'test/unit'
2
2
  require 'yargi'
3
3
 
4
4
  module Yargi
5
-
5
+
6
6
  # Tests all predidate classes
7
7
  class PredicateTest < Test::Unit::TestCase
8
-
8
+
9
9
  def test_to_predicate
10
10
  assert TruePredicate===Predicate.to_predicate(nil)
11
11
  assert TruePredicate===Predicate.to_predicate(true)
@@ -17,26 +17,26 @@ module Yargi
17
17
  assert LambdaPredicate===Predicate.to_predicate(proc)
18
18
  assert AndPredicate === (Predicate.to_predicate(Yargi) {|elm| true})
19
19
  end
20
-
20
+
21
21
  def test_tag_predicate
22
22
  p = TagPredicate.new(Test::Unit::TestCase)
23
23
  assert p===self
24
24
  assert_equal false, p===p
25
25
  end
26
-
26
+
27
27
  def test_lambda_predicate
28
28
  p = LambdaPredicate.new {|elm| Test::Unit::TestCase===elm}
29
29
  assert p===self
30
30
  assert_equal false, p===p
31
31
  end
32
-
32
+
33
33
  def test_not_predicate
34
34
  p = TagPredicate.new(Test::Unit::TestCase)
35
35
  p = NotPredicate.new(p)
36
36
  assert_equal false, p===self
37
37
  assert_equal true, p===p
38
38
  end
39
-
39
+
40
40
  def test_and_predicate
41
41
  assert_equal true, Object===self
42
42
  p1 = TagPredicate.new(Object)
@@ -45,7 +45,7 @@ module Yargi
45
45
  assert_equal true, anded===self
46
46
  assert_equal false, anded==="hello"
47
47
  end
48
-
48
+
49
49
  def test_or_predicate
50
50
  p1 = LambdaPredicate.new {|elm| elm.respond_to?(:upcase)}
51
51
  p2 = LambdaPredicate.new {|elm| elm.respond_to?(:test_and_predicate)}
@@ -54,13 +54,13 @@ module Yargi
54
54
  assert_equal true, ored==="hello"
55
55
  assert_equal false, ored===12
56
56
  end
57
-
57
+
58
58
  def test_not_accepts_modules
59
59
  p = NotPredicate.new(Test::Unit::TestCase)
60
60
  assert_equal false, p===self
61
61
  assert_equal true, p==="hello"
62
62
  end
63
-
63
+
64
64
  def test_ruby_shortcuts
65
65
  all = Yargi::ALL
66
66
  none = Yargi::NONE
@@ -70,21 +70,21 @@ module Yargi
70
70
  p = p.not()
71
71
  assert_equal false, p===self
72
72
  assert_equal true, p==="hello"
73
-
73
+
74
74
  respond = LambdaPredicate.new {|elm| elm.respond_to?(:test_and_predicate)}
75
75
  assert_equal true, respond===self
76
76
  p = all & Test::Unit::TestCase & respond
77
77
  assert_equal true, p===self
78
-
78
+
79
79
  ored = none|all
80
80
  assert_equal true, ored===self
81
-
81
+
82
82
  ored = none|respond|String
83
83
  assert_equal true, ored===self
84
84
  assert_equal true, ored==="hello"
85
85
  assert_equal false, ored===12
86
86
  end
87
-
87
+
88
88
  end # class PredicateTest
89
-
89
+
90
90
  end
Binary file
@@ -2,13 +2,13 @@ require 'test/unit'
2
2
  require 'yargi'
3
3
 
4
4
  module Yargi
5
-
5
+
6
6
  class VertexSetTest < Test::Unit::TestCase
7
-
7
+
8
8
  module Center; end
9
9
  module AtOne; end
10
10
  module AtTwo; end
11
-
11
+
12
12
  def setup
13
13
  @star = Yargi::Digraph.new
14
14
  @center = @star.add_vertex(Center)
@@ -20,13 +20,13 @@ module Yargi
20
20
  end
21
21
  #puts @star.to_dot
22
22
  end
23
-
23
+
24
24
  def test_in_and_out_edges
25
25
  assert_equal [], VertexSet[@center].in_edges
26
26
  assert_equal @atone.in_edges, VertexSet[@center].out_edges
27
27
  assert_equal @attwo.in_edges, @atone.out_edges
28
28
  end
29
-
29
+
30
30
  def test_in_and_out_edges_no_duplicate
31
31
  @star.connect(@atone, @atone)
32
32
  assert_equal @atone.in_edges, @atone.in_edges.uniq
@@ -37,7 +37,7 @@ module Yargi
37
37
  assert_equal @atone.sort(&sortproc), @atone.out_edges.source.sort(&sortproc)
38
38
  assert_equal (@atone+[@center]).sort(&sortproc), @atone.in_edges.source.sort(&sortproc)
39
39
  end
40
-
40
+
41
41
  end # class VertexSetTest
42
-
42
+
43
43
  end
@@ -0,0 +1,187 @@
1
+ # We require your library, mainly to have access to the VERSION number.
2
+ # Feel free to set $version manually.
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
4
+ require "yargi/version"
5
+ $version = Yargi::Version.to_s
6
+
7
+ #
8
+ # This is your Gem specification. Default values are provided so that your library
9
+ # should be correctly packaged given what you have described in the .noespec file.
10
+ #
11
+ Gem::Specification.new do |s|
12
+
13
+ ################################################################### ABOUT YOUR GEM
14
+
15
+ # Gem name (required)
16
+ s.name = "yargi"
17
+
18
+ # Gem version (required)
19
+ s.version = $version
20
+
21
+ # A short summary of this gem
22
+ #
23
+ # This is displayed in `gem list -d`.
24
+ s.summary = "Yet Another Ruby Graph Library "
25
+
26
+ # A long description of this gem (required)
27
+ #
28
+ # The description should be more detailed than the summary. For example,
29
+ # you might wish to copy the entire README into the description.
30
+ s.description = "Yargi provides a powerful mutable digraph implementation. "
31
+
32
+ # The URL of this gem home page (optional)
33
+ s.homepage = "http://github.com/blambeau/yargi"
34
+
35
+ # Gem publication date (required but auto)
36
+ #
37
+ # Today is automatically used by default, uncomment only if
38
+ # you know what you do!
39
+ #
40
+ # s.date = Time.now.strftime('%Y-%m-%d')
41
+
42
+ # The license(s) for the library. Each license must be a short name, no
43
+ # more than 64 characters.
44
+ #
45
+ # s.licences = %w{}
46
+
47
+ # The rubyforge project this gem lives under (optional)
48
+ #
49
+ # s.rubyforge_project = nil
50
+
51
+ ################################################################### ABOUT THE AUTHORS
52
+
53
+ # The list of author names who wrote this gem.
54
+ #
55
+ # If you are providing multiple authors and multiple emails they should be
56
+ # in the same order.
57
+ #
58
+ s.authors = ["Bernard Lambeau"]
59
+
60
+ # Contact emails for this gem
61
+ #
62
+ # If you are providing multiple authors and multiple emails they should be
63
+ # in the same order.
64
+ #
65
+ # NOTE: Somewhat strangly this attribute is always singular!
66
+ # Don't replace by s.emails = ...
67
+ s.email = ["blambeau@gmail.com"]
68
+
69
+ ################################################################### PATHS, FILES, BINARIES
70
+
71
+ # Paths in the gem to add to $LOAD_PATH when this gem is
72
+ # activated (required).
73
+ #
74
+ # The default 'lib' is typically sufficient.
75
+ s.require_paths = ["lib"]
76
+
77
+ # Files included in this gem.
78
+ #
79
+ # By default, we take all files included in the Manifest.txt file on root
80
+ # of the project. Entries of the manifest are interpreted as Dir[...]
81
+ # patterns so that lazy people may use wilcards like lib/**/*
82
+ #
83
+ here = File.expand_path(File.dirname(__FILE__))
84
+ s.files = File.readlines(File.join(here, 'Manifest.txt')).
85
+ inject([]){|files, pattern| files + Dir[File.join(here, pattern.strip)]}.
86
+ collect{|x| x[(1+here.size)..-1]}
87
+
88
+ # Test files included in this gem.
89
+ #
90
+ s.test_files = Dir["test/**/*"] + Dir["spec/**/*"]
91
+
92
+ # The path in the gem for executable scripts (optional)
93
+ #
94
+ s.bindir = "bin"
95
+
96
+ # Executables included in the gem.
97
+ #
98
+ s.executables = (Dir["bin/*"]).collect{|f| File.basename(f)}
99
+
100
+ ################################################################### REQUIREMENTS & INSTALL
101
+ # Remember the gem version requirements operators and schemes:
102
+ # = Equals version
103
+ # != Not equal to version
104
+ # > Greater than version
105
+ # < Less than version
106
+ # >= Greater than or equal to
107
+ # <= Less than or equal to
108
+ # ~> Approximately greater than
109
+ #
110
+ # Don't forget to have a look at http://lmgtfy.com/?q=Ruby+Versioning+Policies
111
+ # for setting your gem version.
112
+ #
113
+ # For your requirements to other gems, remember that
114
+ # ">= 2.2.0" (optimistic: specify minimal version)
115
+ # ">= 2.2.0", "< 3.0" (pessimistic: not greater than the next major)
116
+ # "~> 2.2" (shortcut for ">= 2.2.0", "< 3.0")
117
+ # "~> 2.2.0" (shortcut for ">= 2.2.0", "< 2.3.0")
118
+ #
119
+
120
+ #
121
+ # One call to add_dependency('gem_name', 'gem version requirement') for each
122
+ # runtime dependency. These gems will be installed with your gem.
123
+ # One call to add_development_dependency('gem_name', 'gem version requirement')
124
+ # for each development dependency. These gems are required for developers
125
+ #
126
+ s.add_development_dependency("rake", "~> 0.9.2")
127
+ s.add_development_dependency("rspec", "~> 2.8.0")
128
+ s.add_development_dependency("wlang", "~> 0.10.2")
129
+
130
+
131
+ # The version of ruby required by this gem
132
+ #
133
+ # Uncomment and set this if your gem requires specific ruby versions.
134
+ #
135
+ # s.required_ruby_version = ">= 0"
136
+
137
+ # The RubyGems version required by this gem
138
+ #
139
+ # s.required_rubygems_version = ">= 0"
140
+
141
+ # The platform this gem runs on. See Gem::Platform for details.
142
+ #
143
+ # s.platform = nil
144
+
145
+ # Extensions to build when installing the gem.
146
+ #
147
+ # Valid types of extensions are extconf.rb files, configure scripts
148
+ # and rakefiles or mkrf_conf files.
149
+ #
150
+ s.extensions = []
151
+
152
+ # External (to RubyGems) requirements that must be met for this gem to work.
153
+ # It’s simply information for the user.
154
+ #
155
+ s.requirements = nil
156
+
157
+ # A message that gets displayed after the gem is installed
158
+ #
159
+ # Uncomment and set this if you want to say something to the user
160
+ # after gem installation
161
+ #
162
+ s.post_install_message = nil
163
+
164
+ ################################################################### SECURITY
165
+
166
+ # The key used to sign this gem. See Gem::Security for details.
167
+ #
168
+ # s.signing_key = nil
169
+
170
+ # The certificate chain used to sign this gem. See Gem::Security for
171
+ # details.
172
+ #
173
+ # s.cert_chain = []
174
+
175
+ ################################################################### RDOC
176
+
177
+ # An ARGV style array of options to RDoc
178
+ #
179
+ # See 'rdoc --help' about this
180
+ #
181
+ s.rdoc_options = []
182
+
183
+ # Extra files to add to RDoc such as README
184
+ #
185
+ s.extra_rdoc_files = Dir["README.md"] + Dir["CHANGELOG.md"] + Dir["LICENCE.md"]
186
+
187
+ end