class MyList
Public Class Methods
new(a = [])
click to toggle source
# File lib/testing.rb, line 7 def initialize(a = []) @list = a end
set_correct()
click to toggle source
# File lib/testing.rb, line 108 def self.set_correct alias_method :minimum, :minimum_correct end
set_fast()
click to toggle source
# File lib/testing.rb, line 100 def self.set_fast alias_method :min_max, :min_max_fast end
set_slow()
click to toggle source
# File lib/testing.rb, line 96 def self.set_slow alias_method :min_max, :min_max_slow end
set_wrong()
click to toggle source
# File lib/testing.rb, line 104 def self.set_wrong alias_method :minimum, :minimum_wrong end
Public Instance Methods
append(a)
click to toggle source
# File lib/testing.rb, line 15 def append(a) @list.append(a) end
contents()
click to toggle source
# File lib/testing.rb, line 11 def contents @list end
find_first_position_of(a)
click to toggle source
# File lib/testing.rb, line 19 def find_first_position_of(a) i = 0 position = nil while i < @list.length if @list[i] == a position = i break end i += 1 end return position end
find_positions_of(a)
click to toggle source
# File lib/testing.rb, line 32 def find_positions_of(a) positions = [] i = 0 while i < @list.length if @list[i] == a positions.append i end i += 1 end return positions end
maximum()
click to toggle source
# File lib/testing.rb, line 44 def maximum i = 0 max = @list[0] while i < @list.length if @list[i] > max max = @list[i] end i += 1 end return max end
min_max_fast()
click to toggle source
# File lib/testing.rb, line 84 def min_max_fast i = 0 min = @list[0] max = @list[0] while i < @list.length min = @list[i] if @list[i] < min max = @list[i] if @list[i] > max i += 1 end [min, max] end
min_max_slow()
click to toggle source
# File lib/testing.rb, line 80 def min_max_slow [minimum, maximum] end
minimum_correct()
click to toggle source
# File lib/testing.rb, line 68 def minimum_correct i = 0 min = @list[0] while i < @list.length if @list[i] < min min = @list[i] end i += 1 end return min end
minimum_wrong()
click to toggle source
# File lib/testing.rb, line 56 def minimum_wrong i = 0 min = @list[0] while i < @list.length if @list[i] > min min = @list[i] end i += 1 end return min end