diff options
| author | mo khan <mo@mokhan.ca> | 2014-07-31 21:12:58 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-07-31 21:12:58 -0600 |
| commit | e05094711fe1a42b18af85b64958bb4c2da35848 (patch) | |
| tree | 3524d3e877aa575fc0c88ea45d29e2248b45c84a | |
| parent | 91cc49048409f9dc6bbf28bf520de43c533e612f (diff) | |
extract lets
| -rw-r--r-- | spec/sorting/efficiency_spec.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/spec/sorting/efficiency_spec.rb b/spec/sorting/efficiency_spec.rb index 46bf5de..86505fd 100644 --- a/spec/sorting/efficiency_spec.rb +++ b/spec/sorting/efficiency_spec.rb @@ -1,6 +1,10 @@ require "spec_helper" describe "Algorithm efficiency" do + let(:bubble_sort) { BubbleSort.new } + let(:insertion_sort) { InsertionSort.new } + let(:merge_sort) { MergeSort.new } + let(:quick_sort) { QuickSort.new } it "should sort an array of 100 numbers" do run(100) @@ -21,10 +25,10 @@ describe "Algorithm efficiency" do def run(n) numbers = Array.new(n) { rand(n) } Benchmark.bmbm do |x| - x.report("#{n}-bubble") { BubbleSort.new.sort(numbers) } - x.report("#{n}-insertion") { InsertionSort.new.sort(numbers) } - x.report("#{n}-merge") { MergeSort.new.sort(numbers) } - x.report("#{n}-quick") { QuickSort.new.sort(numbers) } + x.report("#{n}-bubble") { bubble_sort.sort(numbers) } + x.report("#{n}-insertion") { insertion_sort.sort(numbers) } + x.report("#{n}-merge") { merge_sort.sort(numbers) } + x.report("#{n}-quick") { quick_sort.sort(numbers) } x.report("#{n}-ruby") { numbers.sort } end end |
