-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_spec.rb
More file actions
31 lines (26 loc) · 771 Bytes
/
node_spec.rb
File metadata and controls
31 lines (26 loc) · 771 Bytes
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
require "./node.rb"
RSpec.describe Node do
it "initializes" do
node = Node.new(5)
expect(node.data).to eq(5)
end
it "compares nodes using data attribute" do
small_node = Node.new(5)
small_node2 = Node.new(5)
big_node = Node.new(10)
expect(small_node < big_node).to eq(true)
expect(small_node == small_node2).to eq(true)
expect(small_node > big_node).to eq(false)
end
it "is a leaf node when there are no children" do
node = Node.new(5)
expect(node.leaf?).to eq(true)
expect(node.single_parent?).to eq(false)
end
it "is a single parent when there is a single child" do
node = Node.new(5)
node.left = Node.new(4)
expect(node.leaf?).to eq(false)
expect(node.single_parent?).to eq(true)
end
end