Skip to content

Commit 7197332

Browse files
committed
Fix some ruby files using rubocop
1 parent 28d6266 commit 7197332

17 files changed

+41
-44
lines changed

src/ruby/ExponenciacaoTest.rb

-10
This file was deleted.

src/ruby/Palindromo.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# the easiest implementation would be using .reverse method
77

8-
def is_palindrome(string)
8+
def palindrome?(string)
99
return true if string.size == 1 || string.empty?
1010

1111
reversed = ''
@@ -17,8 +17,8 @@ def is_palindrome(string)
1717
reversed == string
1818
end
1919

20-
assert_equal is_palindrome('abba'), true
21-
assert_equal is_palindrome('abbas'), false
22-
assert_equal is_palindrome('tattarrattat'), true
23-
assert_equal is_palindrome('Was it a palindrome?'), false
24-
assert_equal is_palindrome('No lemon, no melon'), true
20+
assert_equal palindrome?('abba'), true
21+
assert_equal palindrome?('abbas'), false
22+
assert_equal palindrome?('tattarrattat'), true
23+
assert_equal palindrome?('Was it a palindrome?'), false
24+
assert_equal palindrome?('No lemon, no melon'), true

src/ruby/bubble_sort.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
# Sort an array using the BubbleSort algorithm
34
class Bubblesort
45
attr_reader :array_sorted
56

src/ruby/bucket_sort.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
require_relative './insertion_sort'
44

5-
class Bucketsort
5+
# Sort an array using the BucketSort algorithm
6+
class BucketSort
67
attr_reader :array_sorted
78

89
def initialize
910
@array_sorted = []
10-
@insertion = Insertionsort.new
11+
@insertion = InsertionSort.new
1112
end
1213

1314
def init(array)
@@ -41,6 +42,6 @@ def bucket_sort(array, bucket_size)
4142
end
4243

4344
# test
44-
bu_s = Bucketsort.new
45+
bu_s = BucketSort.new
4546
bu_s.init([1, 4, 10, 2, 3, 32, 0])
4647
p bu_s.array_sorted
File renamed without changes.
File renamed without changes.

src/ruby/count_sort.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

3-
class Countsort
3+
# Sort an array using the CountSort algorithm
4+
class CountSort
45
attr_reader :array_sorted
56

67
def initialize
@@ -47,6 +48,6 @@ def count_sort(array, min, max)
4748
end
4849

4950
# test
50-
c_s = Countsort.new
51+
c_s = CountSort.new
5152
c_s.init([1, 4, 10, 2, 3, 32, 0])
5253
p c_s.array_sorted

src/ruby/deque.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ def read_rear
4242
end
4343

4444
# checks whether deque is full or not
45-
def is_full
45+
def full?
4646
result = deque.length >= 1 ? 'está' : 'não esta'
4747
"Lista #{result} cheia!"
4848
end
4949

5050
# checks whether deque is empty or not
51-
def is_empty
51+
def empty?
5252
result = deque.empty? ? 'está' : 'não esta'
5353
"Lista #{result} vazia"
5454
end
@@ -67,13 +67,13 @@ def main
6767
puts deque.read_front
6868
puts deque.read_rear
6969

70-
puts deque.is_full
71-
puts deque.is_empty
70+
puts deque.full?
71+
puts deque.empty?
7272

7373
# test with empty list
7474
deque_empty = Deque.new
75-
puts deque_empty.is_full
76-
puts deque_empty.is_empty
75+
puts deque_empty.full?
76+
puts deque_empty.empty?
7777
end
7878

7979
main

src/ruby/heap_sort.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
# Sort an array using the HeapSort algorithm
34
class Heapsort
45
attr_reader :array_sorted
56

src/ruby/insertion_sort.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

3-
class Insertionsort
3+
# Sort an array using the InsertionSort algorithm
4+
class InsertionSort
45
attr_reader :array_sorted
56

67
def initialize
@@ -30,6 +31,6 @@ def insertion_sort(array, compare = ->(a, b) { a <=> b })
3031
end
3132

3233
# test
33-
i_s = Insertionsort.new
34+
i_s = InsertionSort.new
3435
i_s.init([1, 4, 10, 2, 3, 32, 0])
3536
p i_s.array_sorted

src/ruby/interpolation_search.rb

+4-6
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,20 @@ def interpolation_search(value, data)
1414
return "Elemento encontrado na #{high}° posição do array ordenado."
1515
elsif value > data[mid]
1616
low = mid
17-
high = high
1817
mid = ((high - low) / 2).floor + low
1918
else
20-
low = low
2119
high = mid
2220
mid = ((high - low) / 2).floor + low
2321
end
2422
end
2523
end
2624

2725
def main
28-
array_1 = [37, 53, 1, 43, 11, 49, 32, 55, 40, 47, 25, 4].sort
29-
puts interpolation_search(43, array_1) # 8° posição do array ordenado
26+
array1 = [37, 53, 1, 43, 11, 49, 32, 55, 40, 47, 25, 4].sort
27+
puts interpolation_search(43, array1) # 8° posição do array ordenado
3028

31-
array_2 = [23, 9, 5, 78, 123, 5444, 54_535, 64, 3, 12, 14, 15].sort
32-
puts interpolation_search(5444, array_2) # 11° posição do array ordenado
29+
array2 = [23, 9, 5, 78, 123, 5444, 54_535, 64, 3, 12, 14, 15].sort
30+
puts interpolation_search(5444, array2) # 11° posição do array ordenado
3331
end
3432

3533
main

src/ruby/merge_sort.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

3-
class Mergesort
3+
# Sort an array using the MergeSort algorithm
4+
class MergeSort
45
attr_reader :array_sorted
56

67
def initialize
@@ -44,6 +45,6 @@ def merge(left, right)
4445
end
4546

4647
# test
47-
m = Mergesort.new
48+
m = MergeSort.new
4849
m.init([1, 4, 10, 2, 3, 32, 0])
4950
p m.array_sorted

src/ruby/quick_sort.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
# Sort an array using the QuickSort algorithm
34
class Quicksort
45
attr_reader :array_sorted
56

src/ruby/radix_sort.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

3-
class Radixsort
3+
# Sort an array using the RadixSort algorithm
4+
class RadixSort
45
attr_reader :array_sorted
56

67
def initialize
@@ -56,6 +57,6 @@ def radix(array, exp = 0)
5657
end
5758

5859
# test
59-
r_s = Radixsort.new
60+
r_s = RadixSort.new
6061
r_s.init([1, 4, 10, 2, 3, 32, 0])
6162
p r_s.array_sorted

src/ruby/selection_sort.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

3-
class Selectionsort
3+
# Sort an array using the SelectionSort algorithm
4+
class SelectionSort
45
attr_reader :array_sorted
56

67
def initialize
@@ -13,11 +14,11 @@ def init(array)
1314

1415
private
1516

16-
def selection_sort(array, n)
17-
n.times do |i|
17+
def selection_sort(array, size)
18+
size.times do |i|
1819
index_min = i
1920

20-
(i + 1).upto(n) do |j|
21+
(i + 1).upto(size) do |j|
2122
index_min = j if array[j] < array[index_min]
2223
end
2324
array[i], array[index_min] = array[index_min], array[i] if index_min != i
@@ -27,6 +28,6 @@ def selection_sort(array, n)
2728
end
2829

2930
# test
30-
s_s = Selectionsort.new
31+
s_s = SelectionSort.new
3132
s_s.init([1, 4, 10, 2, 3, 32, 0])
3233
p s_s.array_sorted

0 commit comments

Comments
 (0)