Commit c529b96
Changed files (14)
spec
data_structures
euler
traversal
spec/data_structures/avl_tree_spec.rb
@@ -5,11 +5,11 @@ describe AVLTree do
context "when empty" do
it "should have a size of 0" do
- sut.size.should == 0
+ expect(sut.size).to eq(0)
end
it "should have have a height of 0" do
- sut.height.should == 0
+ expect(sut.height).to eq(0)
end
end
@@ -19,11 +19,11 @@ describe AVLTree do
end
it "should have a size of 1" do
- sut.size.should == 1
+ expect(sut.size).to eq(1)
end
it "should have a height of 1" do
- sut.height.should == 1
+ expect(sut.height).to eq(1)
end
end
@@ -34,10 +34,10 @@ describe AVLTree do
end
it "should have a size of 2" do
- sut.size.should == 2
+ expect(sut.size).to eq(2)
end
it "should have a height of 2" do
- sut.height.should == 2
+ expect(sut.height).to eq(2)
end
end
@@ -49,11 +49,11 @@ describe AVLTree do
end
it "should have a size of 3" do
- sut.size.should == 3
+ expect(sut.size).to eq(3)
end
it "should have a height of 2" do
- sut.height.should == 2
+ expect(sut.height).to eq(2)
end
end
@@ -66,19 +66,19 @@ describe AVLTree do
end
it "should re-balance it self" do
- sut.height.should == 2
+ expect(sut.height).to eq(2)
end
it "should have a new root" do
- sut.root.data.should == "b"
+ expect(sut.root.data).to eq("b")
end
it "should change the left side" do
- sut.root.left.data.should == "a"
+ expect(sut.root.left.data).to eq("a")
end
it "should change the right side" do
- sut.root.right.data.should == "c"
+ expect(sut.root.right.data).to eq("c")
end
end
@@ -90,19 +90,19 @@ describe AVLTree do
end
it "should re-balance it self" do
- sut.height.should == 2
+ expect(sut.height).to eq(2)
end
it "should have a new root" do
- sut.root.data.should == "b"
+ expect(sut.root.data).to eq("b")
end
it "should change the left side" do
- sut.root.left.data.should == "a"
+ expect(sut.root.left.data).to eq("a")
end
it "should change the right side" do
- sut.root.right.data.should == "c"
+ expect(sut.root.right.data).to eq("c")
end
end
@@ -114,19 +114,19 @@ describe AVLTree do
end
it "should adjust the height" do
- sut.height.should == 2
+ expect(sut.height).to eq(2)
end
it "should have a new root" do
- sut.root.data.should == 4
+ expect(sut.root.data).to eq(4)
end
it "should have a proper left side" do
- sut.root.left.data.should == 3
+ expect(sut.root.left.data).to eq(3)
end
it "should have a proper right side" do
- sut.root.right.data.should == 5
+ expect(sut.root.right.data).to eq(5)
end
end
@@ -138,19 +138,19 @@ describe AVLTree do
end
it "should adjust the height" do
- sut.height.should == 2
+ expect(sut.height).to eq(2)
end
it "should have a new root" do
- sut.root.data.should == 4
+ expect(sut.root.data).to eq(4)
end
it "should have a proper left side" do
- sut.root.left.data.should == 3
+ expect(sut.root.left.data).to eq(3)
end
it "should have a proper right side" do
- sut.root.right.data.should == 5
+ expect(sut.root.right.data).to eq(5)
end
end
end
spec/data_structures/binary_tree_spec.rb
@@ -8,7 +8,7 @@ describe BinaryTree do
context "when there are no items in the tree" do
it "should have a size of 0" do
- sut.size.should == 0
+ expect(sut.size).to eq(0)
end
end
@@ -20,12 +20,12 @@ describe BinaryTree do
end
it "should increase the size" do
- sut.size.should == 10
+ expect(sut.size).to eq(10)
end
it "can iterate through each item" do
sut.each do |item|
- item.should_not be_nil
+ expect(item).not_to be_nil
end
end
end
spec/data_structures/dynamic_array_stack_spec.rb
@@ -5,7 +5,7 @@ describe DynamicArrayStack do
context "when there is nothing on the stack" do
it "should be able to pop off nil" do
- sut.pop.should be_nil
+ expect(sut.pop).to be_nil
end
end
@@ -13,7 +13,7 @@ describe DynamicArrayStack do
it "should be able to pop it off" do
n = rand
sut.push(n)
- sut.pop.should == n
+ expect(sut.pop).to eq(n)
end
end
@@ -23,7 +23,7 @@ describe DynamicArrayStack do
sut.push(n)
end
(10..0).each do |n|
- sut.pop.should == n
+ expect(sut.pop).to eq(n)
end
end
end
spec/data_structures/hash_table_spec.rb
@@ -4,11 +4,11 @@ describe HashTable do
let(:sut) { HashTable.new }
it "returns a default value" do
- sut[:unkonwn].should be_nil
+ expect(sut[:unkonwn]).to be_nil
end
it "can return the value associated to a key" do
sut[:name] = 'mo'
- sut[:name].should == 'mo'
+ expect(sut[:name]).to eq('mo')
end
end
spec/data_structures/linked_list_stack_spec.rb
@@ -7,7 +7,7 @@ describe LinkedListStack do
let(:result) { sut.pop }
it "should pop nil if there is nothing on the stack" do
- result.should be_nil
+ expect(result).to be_nil
end
end
@@ -20,17 +20,17 @@ describe LinkedListStack do
end
end
it "should pop the last item pushed on to the stack" do
- sut.pop.should == n
+ expect(sut.pop).to eq(n)
end
it "should pop off each item in reverse order of how they were put on" do
(n..1).each do |n|
- sut.pop.should == n
+ expect(sut.pop).to eq(n)
end
end
it "should have the correct number of items" do
- sut.count.should == n
+ expect(sut.count).to eq(n)
end
end
end
spec/euler/problem_one_spec.rb
@@ -10,11 +10,11 @@ end
describe "problem 1" do
it "finds the sum of all multiples of 3 or 5 below 10" do
result = sum_of_all_multiples_under(10)
- result.should == 23
+ expect(result).to eq(23)
end
it "finds the sum of all multiples of 3 or 5 below 1000" do
result = sum_of_all_multiples_under(1000)
- result.should == 233_168
+ expect(result).to eq(233_168)
end
end
spec/practice/binary_search_spec.rb
@@ -20,6 +20,6 @@ describe "binary search" do
it "should find the number" do
items = [0, 5, 13, 19, 22, 41, 55, 68, 72, 81, 98]
result = binary_search(items, 55)
- result.should == 55
+ expect(result).to eq(55)
end
end
spec/practice/fibonacci_spec.rb
@@ -27,14 +27,14 @@ describe "fibonacci" do
xit "should return the correct result" do
#0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144
- sut.get(0).should == 0
- sut.get(1).should == 1
+ expect(sut.get(0)).to eq(0)
+ expect(sut.get(1)).to eq(1)
end
it "should return the first n numbers in fibonacci" do
f = ->(x){ x < 2 ? x : f.call(x-1) + f.call(x-2) }
20.times do |n|
- fibonacci(n).should == f.call(n)
+ expect(fibonacci(n)).to eq(f.call(n))
end
end
@@ -44,7 +44,7 @@ describe "fibonacci" do
it "can do factorial" do
(1..10).each do |n|
- factorial(n).should == (1..n).inject { |total, i| (i) * total }
+ expect(factorial(n)).to eq((1..n).inject { |total, i| (i) * total })
end
end
end
spec/practice/fizzbuzz_spec.rb
@@ -22,21 +22,21 @@ describe FizzBuzz do
it "should return Fizz for multiples of 3" do
sut.print(3, printer)
- printer.string.should == "Fizz"
+ expect(printer.string).to eq("Fizz")
end
it "should return Buzz for multiples of 5" do
sut.print(5, printer)
- printer.string.should == "Buzz"
+ expect(printer.string).to eq("Buzz")
end
it "should return FizzBuzz for multiples of 3 and 5" do
sut.print(15, printer)
- printer.string.should == "FizzBuzz"
+ expect(printer.string).to eq("FizzBuzz")
end
it "should return the number for everything else" do
sut.print(16, printer)
- printer.string.should == "16"
+ expect(printer.string).to eq("16")
end
end
spec/sorting/bubble_sort_spec.rb
@@ -4,18 +4,18 @@ describe BubbleSort do
let(:sut) { BubbleSort.new }
it "should be able to sort an empty array" do
- sut.sort([]).should == []
+ expect(sut.sort([])).to eq([])
end
it "should be able to sort an array with one item" do
- sut.sort([1]).should == [1]
+ expect(sut.sort([1])).to eq([1])
end
it "should be able to sort an array of numbers" do
n = 500
numbers = Array.new(n) { rand(n) }
Benchmark.bmbm do |x|
- x.report("bubble sort") { sut.sort(numbers).should == numbers.sort }
+ x.report("bubble sort") { expect(sut.sort(numbers)).to eq(numbers.sort) }
end
end
end
spec/sorting/insertion_sort_spec.rb
@@ -4,18 +4,18 @@ describe InsertionSort do
let(:sut) { InsertionSort.new }
it "should sort an empty array" do
- sut.sort([]).should == []
+ expect(sut.sort([])).to eq([])
end
it "should sort an array with one item" do
- sut.sort([1]).should == [1]
+ expect(sut.sort([1])).to eq([1])
end
it "should sort an array of numbers" do
n = 200
numbers = Array.new(n) { rand(n) }
Benchmark.bmbm do |x|
- x.report("insertion sort") { sut.sort(numbers).should == numbers.sort }
+ x.report("insertion sort") { expect(sut.sort(numbers)).to eq(numbers.sort) }
end
end
end
spec/sorting/merge_sort_spec.rb
@@ -4,17 +4,17 @@ describe MergeSort do
let(:sut) { MergeSort.new }
it "should sort an empty array" do
- sut.sort([]).should == []
+ expect(sut.sort([])).to eq([])
end
it "should sort an array with one item" do
- sut.sort([2]).should == [2]
+ expect(sut.sort([2])).to eq([2])
end
it "should sort an array of numbers" do
n = 601
numbers = Array.new(n) { rand(n) }
sorted_numbers = numbers.sort
- sut.sort(numbers).should == sorted_numbers
+ expect(sut.sort(numbers)).to eq(sorted_numbers)
end
end
spec/sorting/quick_sort_spec.rb
@@ -13,11 +13,11 @@ describe QuickSort do
let(:sut) { QuickSort.new }
it "should sort an empty array" do
- sut.sort([]).should == []
+ expect(sut.sort([])).to eq([])
end
it "should sort an array with one item" do
- sut.sort([1]).should == [1]
+ expect(sut.sort([1])).to eq([1])
end
it "should sort an array of numbers" do
@@ -25,7 +25,7 @@ describe QuickSort do
numbers = Array.new(n) { rand(n) }
sorted_numbers = numbers.sort
Benchmark.bmbm do |x|
- x.report("quick sort") { sut.sort(numbers).should == sorted_numbers }
+ x.report("quick sort") { expect(sut.sort(numbers)).to eq(sorted_numbers) }
end
end
end
spec/traversal/in_order_traversal_spec.rb
@@ -8,20 +8,20 @@ describe "inorder traversal" do
let(:visitor) { double('visitor', :visit => nil) }
before :each do
- node.stub(:left).and_return(left_node)
- node.stub(:right).and_return(right_node)
+ allow(node).to receive(:left).and_return(left_node)
+ allow(node).to receive(:right).and_return(right_node)
sut.traverse(node, visitor)
end
it "should visit the left node first" do
- visitor.should have_received(:visit).with(left_node)
+ expect(visitor).to have_received(:visit).with(left_node)
end
it "should visit the current node second" do
- visitor.should have_received(:visit).with(node)
+ expect(visitor).to have_received(:visit).with(node)
end
it "should visit the right node last" do
- visitor.should have_received(:visit).with(right_node)
+ expect(visitor).to have_received(:visit).with(right_node)
end
end