Permalink
Browse files

JRuby fixes

  • Loading branch information...
1 parent 454a0a7 commit dae5730894fa573b2a3e4ffcc3cdf635bcf52251 @kanwei committed Jan 22, 2013
Showing with 44 additions and 32 deletions.
  1. +1 −0 .gitignore
  2. +5 −1 Rakefile
  3. +4 −2 algorithms.gemspec
  4. +1 −0 lib/algorithms/string.rb
  5. +23 −21 spec/map_gc_mark_spec.rb
  6. +10 −8 spec/string_spec.rb
View
@@ -9,3 +9,4 @@ pkg
*#
Gemfile.lock
*.gem
+.ruby-version
View
@@ -11,4 +11,8 @@ Rake::ExtensionTask.new('containers/splaytree_map') { |ext| ext.name = "CSplayTr
RSpec::Core::RakeTask.new
-task :default => [:compile, :spec]
+if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
+ task :default => [:spec]
+else
+ task :default => [:compile, :spec]
+end
View
@@ -10,8 +10,10 @@ Gem::Specification.new do |s|
s.date = "2012-04-25"
s.summary = "Useful algorithms and data structures for Ruby. Optional C extensions."
s.description = "Heap, Priority Queue, Deque, Stack, Queue, Red-Black Trees, Splay Trees, sorting algorithms, and more"
- s.extensions = ["ext/algorithms/string/extconf.rb", "ext/containers/bst/extconf.rb", "ext/containers/deque/extconf.rb", "ext/containers/rbtree_map/extconf.rb", "ext/containers/splaytree_map/extconf.rb"]
- s.files = ["CHANGELOG.markdown", "Manifest", "README.markdown", "Rakefile", "algorithms.gemspec", "benchmarks/deque.rb", "benchmarks/sorts.rb", "benchmarks/treemaps.rb", "ext/algorithms/string/extconf.rb", "ext/algorithms/string/string.c", "ext/containers/bst/bst.c", "ext/containers/bst/extconf.rb", "ext/containers/deque/deque.c", "ext/containers/deque/extconf.rb", "ext/containers/rbtree_map/extconf.rb", "ext/containers/rbtree_map/rbtree.c", "ext/containers/splaytree_map/extconf.rb", "ext/containers/splaytree_map/splaytree.c", "lib/algorithms.rb", "lib/algorithms/search.rb", "lib/algorithms/sort.rb", "lib/algorithms/string.rb", "lib/containers/deque.rb", "lib/containers/heap.rb", "lib/containers/kd_tree.rb", "lib/containers/priority_queue.rb", "lib/containers/queue.rb", "lib/containers/rb_tree_map.rb", "lib/containers/splay_tree_map.rb", "lib/containers/stack.rb", "lib/containers/suffix_array.rb", "lib/containers/trie.rb", "spec/bst_gc_mark_spec.rb", "spec/bst_spec.rb", "spec/deque_gc_mark_spec.rb", "spec/deque_spec.rb", "spec/heap_spec.rb", "spec/kd_expected_out.txt", "spec/kd_test_in.txt", "spec/kd_tree_spec.rb", "spec/map_gc_mark_spec.rb", "spec/priority_queue_spec.rb", "spec/queue_spec.rb", "spec/rb_tree_map_spec.rb", "spec/search_spec.rb", "spec/sort_spec.rb", "spec/splay_tree_map_spec.rb", "spec/stack_spec.rb", "spec/string_spec.rb", "spec/suffix_array_spec.rb", "spec/trie_spec.rb"]
+ unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
+ s.extensions = ["ext/algorithms/string/extconf.rb", "ext/containers/bst/extconf.rb", "ext/containers/deque/extconf.rb", "ext/containers/rbtree_map/extconf.rb", "ext/containers/splaytree_map/extconf.rb"]
+ end
+ s.files = ["Gemfile", "CHANGELOG.markdown", "Manifest", "README.markdown", "Rakefile", "algorithms.gemspec", "benchmarks/deque.rb", "benchmarks/sorts.rb", "benchmarks/treemaps.rb", "ext/algorithms/string/extconf.rb", "ext/algorithms/string/string.c", "ext/containers/bst/bst.c", "ext/containers/bst/extconf.rb", "ext/containers/deque/deque.c", "ext/containers/deque/extconf.rb", "ext/containers/rbtree_map/extconf.rb", "ext/containers/rbtree_map/rbtree.c", "ext/containers/splaytree_map/extconf.rb", "ext/containers/splaytree_map/splaytree.c", "lib/algorithms.rb", "lib/algorithms/search.rb", "lib/algorithms/sort.rb", "lib/algorithms/string.rb", "lib/containers/deque.rb", "lib/containers/heap.rb", "lib/containers/kd_tree.rb", "lib/containers/priority_queue.rb", "lib/containers/queue.rb", "lib/containers/rb_tree_map.rb", "lib/containers/splay_tree_map.rb", "lib/containers/stack.rb", "lib/containers/suffix_array.rb", "lib/containers/trie.rb", "spec/bst_gc_mark_spec.rb", "spec/bst_spec.rb", "spec/deque_gc_mark_spec.rb", "spec/deque_spec.rb", "spec/heap_spec.rb", "spec/kd_expected_out.txt", "spec/kd_test_in.txt", "spec/kd_tree_spec.rb", "spec/map_gc_mark_spec.rb", "spec/priority_queue_spec.rb", "spec/queue_spec.rb", "spec/rb_tree_map_spec.rb", "spec/search_spec.rb", "spec/sort_spec.rb", "spec/splay_tree_map_spec.rb", "spec/stack_spec.rb", "spec/string_spec.rb", "spec/suffix_array_spec.rb", "spec/trie_spec.rb"]
s.homepage = "https://github.com/kanwei/algorithms"
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Algorithms", "--main", "README.markdown"]
s.require_paths = ["lib", "ext"]
@@ -5,4 +5,5 @@
begin
require 'CString'
+rescue LoadError
end
@@ -1,27 +1,29 @@
$: << File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
require 'algorithms'
-describe "map gc mark test" do
- it "should mark ruby object references" do
- anon_key_class = Class.new do
- attr :value
- def initialize(x); @value = x; end
- def <=>(other); value <=> other.value; end
+if !(defined? RUBY_ENGINE && RUBY_ENGINE == 'jruby')
+ describe "map gc mark test" do
+ it "should mark ruby object references" do
+ anon_key_class = Class.new do
+ attr :value
+ def initialize(x); @value = x; end
+ def <=>(other); value <=> other.value; end
+ end
+ anon_val_class = Class.new
+ @rbtree = Containers::RBTreeMap.new
+ @splaytree = Containers::SplayTreeMap.new
+ 100.times { |x|
+ @rbtree[anon_key_class.new(x)] = anon_val_class.new
+ @splaytree[anon_key_class.new(x)] = anon_val_class.new
+ }
+ # Mark and sweep
+ ObjectSpace.garbage_collect
+ # Check if any instances were swept
+ count = 0
+ ObjectSpace.each_object(anon_key_class) { |x| count += 1 }
+ count.should eql(200)
+ ObjectSpace.each_object(anon_val_class) { |x| count += 1 }
+ count.should eql(400)
end
- anon_val_class = Class.new
- @rbtree = Containers::CRBTreeMap.new
- @splaytree = Containers::CSplayTreeMap.new
- 100.times { |x|
- @rbtree[anon_key_class.new(x)] = anon_val_class.new
- @splaytree[anon_key_class.new(x)] = anon_val_class.new
- }
- # Mark and sweep
- ObjectSpace.garbage_collect
- # Check if any instances were swept
- count = 0
- ObjectSpace.each_object(anon_key_class) { |x| count += 1 }
- count.should eql(200)
- ObjectSpace.each_object(anon_val_class) { |x| count += 1 }
- count.should eql(400)
end
end
View
@@ -1,13 +1,15 @@
$: << File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
require 'algorithms'
-describe "string algorithms" do
- it "should do levenshtein distance" do
- Algorithms::String.levenshtein_dist("Hello", "Hel").should eql(2)
- Algorithms::String.levenshtein_dist("Hello", "").should eql(5)
- Algorithms::String.levenshtein_dist("", "Hello").should eql(5)
- Algorithms::String.levenshtein_dist("Hello", "Hello").should eql(0)
- Algorithms::String.levenshtein_dist("Hello", "ello").should eql(1)
- Algorithms::String.levenshtein_dist("Hello", "Mello").should eql(1)
+if defined? Algorithms::String
+ describe "string algorithms" do
+ it "should do levenshtein distance" do
+ Algorithms::String.levenshtein_dist("Hello", "Hel").should eql(2)
+ Algorithms::String.levenshtein_dist("Hello", "").should eql(5)
+ Algorithms::String.levenshtein_dist("", "Hello").should eql(5)
+ Algorithms::String.levenshtein_dist("Hello", "Hello").should eql(0)
+ Algorithms::String.levenshtein_dist("Hello", "ello").should eql(1)
+ Algorithms::String.levenshtein_dist("Hello", "Mello").should eql(1)
+ end
end
end

0 comments on commit dae5730

Please sign in to comment.