From d875b4087e3ef632f762c3c0b990f6ed1315df2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jos=C3=A9?= Date: Wed, 17 Dec 2025 11:49:31 -0300 Subject: [PATCH 1/6] feat(contributing): add initial content to CONTRIBUTING.md --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e69de29..6f16acb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -0,0 +1 @@ +teste From 7eb63baa060004cdb2b5aded51d6783a0022ac94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jos=C3=A9?= Date: Wed, 17 Dec 2025 17:18:05 -0300 Subject: [PATCH 2/6] feat(spec): add automatic loading of support files --- spec/spec_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f0e5ec3..0b36bd3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,4 +23,6 @@ # Executa os testes em ordem aleatória para detectar dependências ocultas config.order = :random Kernel.srand(config.seed) + + Dir[File.join(__dir__, "support/**/*.rb")].sort.each { |f| require f } end From 374594b3bdd306b4989f9b910bd8b46986eb4496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jos=C3=A9?= Date: Wed, 17 Dec 2025 17:18:19 -0300 Subject: [PATCH 3/6] feat(tests): add shared examples for sorting algorithms --- .../shared_examples/sorting_algorithms.rb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 spec/support/shared_examples/sorting_algorithms.rb diff --git a/spec/support/shared_examples/sorting_algorithms.rb b/spec/support/shared_examples/sorting_algorithms.rb new file mode 100644 index 0000000..4a04174 --- /dev/null +++ b/spec/support/shared_examples/sorting_algorithms.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +RSpec.shared_examples("a sorting algorithm") do + describe ".call" do + it "returns an ascending sorted array" do + expect(described_class.call([10, 4, 8, 3, 11])) + .to(eq([3, 4, 8, 10, 11])) + end + + it "returns an ascending sorted array with repeating numbers" do + expect(described_class.call([10, 10, 8, 8, 11])) + .to(eq([8, 8, 10, 10, 11])) + end + + it "returns an ascending sorted array with zeros and negative numbers" do + expect(described_class.call([0, -1, -20, 8, 11])) + .to(eq([-20, -1, 0, 8, 11])) + end + end +end From 307505aaef1ff5339eb5abae9ea9c2052025e913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jos=C3=A9?= Date: Wed, 17 Dec 2025 17:18:56 -0300 Subject: [PATCH 4/6] feat: implement QuickSort algorithm and corresponding specs --- lib/sorting_algorithms/quick_sort.rb | 26 ++++++++++++++++++++++ spec/sorting_algorithms/quick_sort_spec.rb | 7 ++++++ 2 files changed, 33 insertions(+) create mode 100644 lib/sorting_algorithms/quick_sort.rb create mode 100644 spec/sorting_algorithms/quick_sort_spec.rb diff --git a/lib/sorting_algorithms/quick_sort.rb b/lib/sorting_algorithms/quick_sort.rb new file mode 100644 index 0000000..af475f4 --- /dev/null +++ b/lib/sorting_algorithms/quick_sort.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module SortingAlgorithms + module QuickSort + class << self + def call(array) + return array if array.length <= 1 + + pivot = array.last + left = [] + right = [] + + array[0...-1].each do |element| + if element <= pivot + left << element + + else + right << element + end + end + + call(left) + [pivot] + call(right) + end + end + end +end diff --git a/spec/sorting_algorithms/quick_sort_spec.rb b/spec/sorting_algorithms/quick_sort_spec.rb new file mode 100644 index 0000000..20c7b77 --- /dev/null +++ b/spec/sorting_algorithms/quick_sort_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe(SortingAlgorithms::QuickSort) do + it_behaves_like "a sorting algorithm" +end From 4dfcb89f7f96ce5575238eef3d3e73f8a6bcfa3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jos=C3=A9?= Date: Wed, 17 Dec 2025 17:19:21 -0300 Subject: [PATCH 5/6] feat: add QuickSort to the sorting algorithms module --- lib/sorting_algorithms.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/sorting_algorithms.rb b/lib/sorting_algorithms.rb index 6852b42..bf01ee9 100644 --- a/lib/sorting_algorithms.rb +++ b/lib/sorting_algorithms.rb @@ -4,6 +4,7 @@ require_relative "sorting_algorithms/insertion_sort" require_relative "sorting_algorithms/selection_sort" require_relative "sorting_algorithms/merge_sort" +require_relative "sorting_algorithms/quick_sort" module SortingAlgorithms end From 16c4e55639552dc0e41d6f613b15f296119ab90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jos=C3=A9?= Date: Wed, 17 Dec 2025 17:19:36 -0300 Subject: [PATCH 6/6] feat(tests): refactor sorting algorithm specs to use shared examples --- spec/sorting_algorithms/bubble_sort_spec.rb | 17 +---------------- spec/sorting_algorithms/insertion_sort_spec.rb | 17 +---------------- spec/sorting_algorithms/merge_sort_spec.rb | 17 +---------------- spec/sorting_algorithms/selection_sort_spec.rb | 17 +---------------- 4 files changed, 4 insertions(+), 64 deletions(-) diff --git a/spec/sorting_algorithms/bubble_sort_spec.rb b/spec/sorting_algorithms/bubble_sort_spec.rb index 75e047f..3ce8cce 100644 --- a/spec/sorting_algorithms/bubble_sort_spec.rb +++ b/spec/sorting_algorithms/bubble_sort_spec.rb @@ -3,20 +3,5 @@ require "spec_helper" RSpec.describe(SortingAlgorithms::BubbleSort) do - describe ".call" do - it "returns an ascending sorted array" do - expect(described_class.call([10, 4, 8, 3, 11])) - .to(eq([3, 4, 8, 10, 11])) - end - - it "returns an ascending sorted array with repeating numbers" do - expect(described_class.call([10, 10, 8, 8, 11])) - .to(eq([8, 8, 10, 10, 11])) - end - - it "returns an ascending sorted array with zeros and negative numbers" do - expect(described_class.call([0, -1, -20, 8, 11])) - .to(eq([-20, -1, 0, 8, 11])) - end - end + it_behaves_like "a sorting algorithm" end diff --git a/spec/sorting_algorithms/insertion_sort_spec.rb b/spec/sorting_algorithms/insertion_sort_spec.rb index 0e71b92..06739e6 100644 --- a/spec/sorting_algorithms/insertion_sort_spec.rb +++ b/spec/sorting_algorithms/insertion_sort_spec.rb @@ -3,20 +3,5 @@ require "spec_helper" RSpec.describe(SortingAlgorithms::InsertionSort) do - describe ".call" do - it "returns an ascending sorted array" do - expect(described_class.call([10, 4, 8, 3, 11])) - .to(eq([3, 4, 8, 10, 11])) - end - - it "returns an ascending sorted array with repeating numbers" do - expect(described_class.call([10, 10, 8, 8, 11])) - .to(eq([8, 8, 10, 10, 11])) - end - - it "returns an ascending sorted array with zeros and negative numbers" do - expect(described_class.call([0, -1, -20, 8, 11])) - .to(eq([-20, -1, 0, 8, 11])) - end - end + it_behaves_like "a sorting algorithm" end diff --git a/spec/sorting_algorithms/merge_sort_spec.rb b/spec/sorting_algorithms/merge_sort_spec.rb index 67594e4..84b51a0 100644 --- a/spec/sorting_algorithms/merge_sort_spec.rb +++ b/spec/sorting_algorithms/merge_sort_spec.rb @@ -3,20 +3,5 @@ require "spec_helper" RSpec.describe(SortingAlgorithms::MergeSort) do - describe ".call" do - it "return an ascending sorted array" do - expect(described_class.call([10, 4, 8, 3, 11])) - .to(eq([3, 4, 8, 10, 11])) - end - - it "return an ascending sorted array with repeating numbers" do - expect(described_class.call([10, 10, 8, 8, 11])) - .to(eq([8, 8, 10, 10, 11])) - end - - it "returns an ascending sorted array with zeros and negative numbers" do - expect(described_class.call([0, -1, -20, 8, 11])) - .to(eq([-20, -1, 0, 8, 11])) - end - end + it_behaves_like "a sorting algorithm" end diff --git a/spec/sorting_algorithms/selection_sort_spec.rb b/spec/sorting_algorithms/selection_sort_spec.rb index 5da8407..9bed3fa 100644 --- a/spec/sorting_algorithms/selection_sort_spec.rb +++ b/spec/sorting_algorithms/selection_sort_spec.rb @@ -3,20 +3,5 @@ require "spec_helper" RSpec.describe(SortingAlgorithms::SelectionSort) do - describe ".call" do - it "return an ascending sorted array" do - expect(described_class.call([10, 4, 8, 3, 11])) - .to(eq([3, 4, 8, 10, 11])) - end - - it "return an ascending sorted array with repeating numbers" do - expect(described_class.call([10, 10, 8, 8, 11])) - .to(eq([8, 8, 10, 10, 11])) - end - - it "returns an ascending sorted array with zeros and negative numbers" do - expect(described_class.call([0, -1, -20, 8, 11])) - .to(eq([-20, -1, 0, 8, 11])) - end - end + it_behaves_like "a sorting algorithm" end