Мне бы такую память... Тогда все еще проще:
Код | require 'test/unit'
def mono_up input_arr result = 0
input_arr.each_with_index do |item, index| if index == 0 result += 1 if item < input_arr[index+1] elsif index != input_arr.size - 1 result += 1 if (input_arr[index-1] >= item && item < input_arr[index+1]) end end if input_arr.size > 1 # we need at least 2 items in row to find one monoup result end
class MonoUp < Test::Unit::TestCase def test_for_truth test_arr_1, test_res_1 = [1, 2, 3, 4 ,5, 41, 11, 9, 6, 7, 0], 2 test_arr_2, test_res_2 = [1, 3, 4, 6, 7, 8, 10, 11], 1 test_arr_3, test_res_3 = [1, 2, 3, 4, 6, 7, 8, 10, 11], 1 test_arr_4, test_res_4 = [9, 1, 3, 4, 6, 7, 8, 10, 11, 12, 1, 9, 11], 2 test_arr_5, test_res_5 = [1, 2, 3, 4, 1, 8, 10, 1, 16, 17], 3 test_arr_6, test_res_6 = [1, 3, 4, 6, 9, 10, 5, 16, 19], 2 test_arr_7, test_res_7 = [1, 4, 3], 1 test_arr_8, test_res_8 = [1, 2, 4], 1 test_arr_9, test_res_9 = [1], 0 test_arr_10, test_res_10 = [1, 3], 1 test_arr_11, test_res_11 = [1, 2, 1, 3], 2
assert defined?(mono_up) assert_equal mono_up(test_arr_1), test_res_1 assert_equal mono_up(test_arr_2), test_res_2 assert_equal mono_up(test_arr_3), test_res_3 assert_equal mono_up(test_arr_4), test_res_4 assert_equal mono_up(test_arr_5), test_res_5 assert_equal mono_up(test_arr_6), test_res_6 assert_equal mono_up(test_arr_7), test_res_7 assert_equal mono_up(test_arr_8), test_res_8 assert_equal mono_up(test_arr_9), test_res_9 assert_equal mono_up(test_arr_10), test_res_10 assert_equal mono_up(test_arr_11), test_res_11 end end
|
|