Skip to content

Commit 1dbbfc4

Browse files
committed
Move lang specific tests
1 parent 2a866d6 commit 1dbbfc4

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

exercises/binary-search-tree/spec/binary_search_tree_spec.cr

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "spec"
22
require "../src/*"
33

4-
describe "Node" do
4+
describe "BinarySearchTree" do
55
it "sets the root node" do
66
root = Node.new(1)
77
root.value.should eq(1)
@@ -66,40 +66,6 @@ describe "Node" do
6666
value.should eq(test_array.shift)
6767
end
6868
end
69-
70-
# Bonus!
71-
pending "is an Enumerable" do
72-
tree = Node.new(1)
73-
tree.insert(5)
74-
tree.insert(2)
75-
tree.should be_a(Enumerable(Int32))
76-
mapped_values = tree.map { |value| value * 10 }
77-
mapped_values.should eq([10, 20, 50])
78-
end
79-
80-
# Advanced
81-
pending "will return an iterator if no block is provided" do
82-
tree = Node.new(1)
83-
tree.insert(5)
84-
tree.insert(2)
85-
iter = tree.each
86-
iter.next.should eq 1
87-
iter.next.should eq 2
88-
iter.next.should eq 5
89-
end
90-
91-
# Bonus!
92-
pending "is Iterable" do
93-
tree = Node.new(100)
94-
tree.insert(50)
95-
tree.insert(20)
96-
tree.insert(30)
97-
tree.should be_a(Iterable(Int32))
98-
iter = tree.each_cons(2)
99-
iter.next.should eq([20, 30])
100-
iter.next.should eq([30, 50])
101-
iter.next.should eq([50, 100])
102-
end
10369
end
10470

10571
# Deletion from a binary search tree https://en.wikipedia.org/wiki/Binary_search_tree#Deletion
@@ -179,4 +145,46 @@ describe "Node" do
179145
end
180146
end
181147
end
148+
149+
# The following tests check for additional features to the Binary Search Tree
150+
# They are not required to implement a complete BST
151+
# Instead they should be used to dive a little deeper into the Crystal language
152+
describe "crystal-lang specific" do
153+
# Make the Binary Search Tree Enumerable
154+
# See https://crystal-lang.org/api/0.20.3/Enumerable.html
155+
pending "is an Enumerable" do
156+
tree = Node.new(1)
157+
tree.insert(5)
158+
tree.insert(2)
159+
tree.should be_a(Enumerable(Int32))
160+
mapped_values = tree.map { |value| value * 10 }
161+
mapped_values.should eq([10, 20, 50])
162+
end
163+
164+
# If no block is provided to the each method return an Iterator
165+
# See https://crystal-lang.org/api/0.20.3/Iterator.html
166+
pending "will return an iterator if no block is provided" do
167+
tree = Node.new(1)
168+
tree.insert(5)
169+
tree.insert(2)
170+
iter = tree.each
171+
iter.next.should eq 1
172+
iter.next.should eq 2
173+
iter.next.should eq 5
174+
end
175+
176+
# Make the Binary Search Tree Iterable
177+
# See https://crystal-lang.org/api/0.20.3/Iterable.html
178+
pending "is Iterable" do
179+
tree = Node.new(100)
180+
tree.insert(50)
181+
tree.insert(20)
182+
tree.insert(30)
183+
tree.should be_a(Iterable(Int32))
184+
iter = tree.each_cons(2)
185+
iter.next.should eq([20, 30])
186+
iter.next.should eq([30, 50])
187+
iter.next.should eq([50, 100])
188+
end
189+
end
182190
end

0 commit comments

Comments
 (0)