@@ -3,13 +3,13 @@ require "../src/*"
3
3
4
4
describe " Node" do
5
5
it " sets the root node" do
6
- root = Node ( Int32 ) .new(1 )
6
+ root = Node .new(1 )
7
7
root.value.should eq(1 )
8
8
end
9
9
10
10
describe " #insert" do
11
11
pending " inserts smaller values to the left" do
12
- tree = Node ( Int32 ) .new(4 )
12
+ tree = Node .new(4 )
13
13
tree.insert(2 )
14
14
15
15
left = tree.left.not_nil!
@@ -19,7 +19,7 @@ describe "Node" do
19
19
end
20
20
21
21
pending " inserts equal values to the left" do
22
- tree = Node ( Int32 ) .new(4 )
22
+ tree = Node .new(4 )
23
23
tree.insert(4 )
24
24
25
25
left_node = tree.left.not_nil!
@@ -29,7 +29,7 @@ describe "Node" do
29
29
end
30
30
31
31
pending " inserts greater values to the right" do
32
- tree = Node ( Int32 ) .new(4 )
32
+ tree = Node .new(4 )
33
33
tree.insert(5 )
34
34
35
35
right_node = tree.right.not_nil!
@@ -41,21 +41,21 @@ describe "Node" do
41
41
42
42
describe " #search" do
43
43
pending " will return a node if a search if successful" do
44
- tree = Node ( Int32 ) .new(5 )
44
+ tree = Node .new(5 )
45
45
tree.insert(1 )
46
46
node = tree.search(1 ).not_nil!
47
47
node.value.should eq(1 )
48
48
end
49
49
50
50
pending " will return nil if a searched value is not found" do
51
- tree = Node ( Int32 ) .new(5 )
51
+ tree = Node .new(5 )
52
52
tree.search(4 ).should be_nil
53
53
end
54
54
end
55
55
56
56
describe " #each" do
57
57
pending " traverses the tree in order" do
58
- tree = Node ( Int32 ) .new(5 )
58
+ tree = Node .new(5 )
59
59
tree.insert(1 )
60
60
tree.insert(6 )
61
61
tree.insert(7 )
@@ -69,7 +69,7 @@ describe "Node" do
69
69
70
70
# Bonus!
71
71
pending " is an Enumerable" do
72
- tree = Node ( Int32 ) .new(1 )
72
+ tree = Node .new(1 )
73
73
tree.insert(5 )
74
74
tree.insert(2 )
75
75
tree.should be_a(Enumerable (Int32 ))
@@ -79,7 +79,7 @@ describe "Node" do
79
79
80
80
# Advanced
81
81
pending " will return an iterator if no block is provided" do
82
- tree = Node ( Int32 ) .new(1 )
82
+ tree = Node .new(1 )
83
83
tree.insert(5 )
84
84
tree.insert(2 )
85
85
iter = tree.each
@@ -90,7 +90,7 @@ describe "Node" do
90
90
91
91
# Bonus!
92
92
pending " is Iterable" do
93
- tree = Node ( Int32 ) .new(100 )
93
+ tree = Node .new(100 )
94
94
tree.insert(50 )
95
95
tree.insert(20 )
96
96
tree.insert(30 )
@@ -109,21 +109,21 @@ describe "Node" do
109
109
# 3. Deleting a node with two children
110
110
describe " #delete" do
111
111
pending " can remove the root node" do
112
- tree = Node ( Int32 ) .new(5 )
112
+ tree = Node .new(5 )
113
113
tree.insert(2 )
114
114
tree.delete(5 )
115
115
tree.value.should eq(2 )
116
116
end
117
117
118
118
pending " removes a node with no children" do
119
- tree = Node ( Int32 ) .new(5 )
119
+ tree = Node .new(5 )
120
120
tree.insert(2 )
121
121
tree.delete(2 )
122
122
tree.left.should be_nil
123
123
end
124
124
125
125
pending " removes a node with one child" do
126
- tree = Node ( Int32 ) .new(5 )
126
+ tree = Node .new(5 )
127
127
tree.insert(3 )
128
128
tree.insert(2 )
129
129
tree.delete(3 )
@@ -135,7 +135,7 @@ describe "Node" do
135
135
end
136
136
137
137
pending " removes a node with two children" do
138
- tree = Node ( Int32 ) .new(5 )
138
+ tree = Node .new(5 )
139
139
tree.insert(3 )
140
140
tree.insert(2 )
141
141
tree.insert(4 )
@@ -148,7 +148,7 @@ describe "Node" do
148
148
end
149
149
150
150
pending " removes a left node with two child (complex)" do
151
- tree = Node ( Int32 ) .new(10 )
151
+ tree = Node .new(10 )
152
152
tree.insert(5 )
153
153
tree.insert(2 )
154
154
tree.insert(4 )
@@ -164,7 +164,7 @@ describe "Node" do
164
164
end
165
165
166
166
pending " removes a right node with two children (complex)" do
167
- tree = Node ( Int32 ) .new(1 )
167
+ tree = Node .new(1 )
168
168
tree.insert(5 )
169
169
tree.insert(2 )
170
170
tree.insert(4 )
0 commit comments