Permalink
Browse files

alias_method :size, :count, since :count is provided by Enumerable.

Also whitespace, because my editor hates whitespace.
  • Loading branch information...
1 parent e6b72d3 commit 72c1866de7bff14d87cec21fb4ef6561aa924f04 @hypomodern hypomodern committed May 23, 2012
Showing with 12 additions and 5 deletions.
  1. +3 −5 lib/bracket_tree/bracket.rb
  2. +9 −0 spec/unit/bracket_tree/bracket_spec.rb
@@ -7,7 +7,7 @@ class SeedLimitExceededError < Exception ; end
include Enumerable
attr_accessor :root, :seed_order, :insertion_order
-
+
def initialize
@insertion_order = []
end
@@ -99,14 +99,12 @@ def nodes
to_a.sort_by { |node| @insertion_order.index(node.position) }
end
- def size
- @insertion_order.size
- end
+ alias_method :size, :count
def in_order(node, block)
if node
unless node.left.nil?
- in_order(node.left, block)
+ in_order(node.left, block)
end
block.call(node)
@@ -105,6 +105,15 @@
end
end
+ describe "#size" do
+ it "should return the number of nodes in the bracket" do
+ bracket.add 3, { foo: 'foo' }
+ bracket.add 2, { bar: 'bar' }
+ bracket.add 4, { baz: 'baz' }
+ bracket.size.should == 3
+ end
+ end
+
describe '#seed' do
let(:bracket) { BracketTree::Template::SingleElimination.by_size(4).generate_blank_bracket }
let(:players) do

0 comments on commit 72c1866

Please sign in to comment.