summaryrefslogtreecommitdiff
path: root/spec/data_structures/binary_tree_spec.rb
blob: 348be6fbbff45c8d9450bcfaefc83c51909fb1f8 (plain)
1
2
3
4
5
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
require "spec_helper"

#Tree data structure
#each node has at most two children
#nodes with children are parent nodes.
describe BinaryTree do
  subject { BinaryTree.new }

  context "when there are no items in the tree" do
    it "should have a size of 0" do
      expect(subject.size).to eq(0)
    end
  end

  context "when many items are pushed on to the tree" do
    before :each do
      10.times do |n|
        subject.push(rand(n))
      end
    end

    it "should increase the size" do
      expect(subject.size).to eq(10)
    end

    it "can iterate through each item" do
      subject.each do |item|
        expect(item).not_to be_nil
      end
    end
  end
end