Skip to content

Commit

Permalink
Update README.md, added skeleton file and test file
Browse files Browse the repository at this point in the history
  • Loading branch information
Murchibik committed Feb 9, 2022
1 parent 4413877 commit 52d8edd
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 3 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# test-task-skeleton
Repository for test task for Ruby Internship 2022
**Repository for test task for Ruby Internship 2022**

As contestant you should fork this repository, add needed code and create contribute request to main repository.
As participant you should fork this repository, add needed code in file `test_skeleton.rb` and create contribute request to main repository.

Tests should be passed before creating contribute request.
Beforehand you should install Ruby 2.7 and gem Rspec (`gem install rspec`)

Tests should be passed before creating contribute request. For running tests you should run `ruby test.rb` in directory of repository

List of tasks to implement(All credits to https://codewars.com):
* even_or_odd -> test_skeleton.rb:12
* reverse_array -> test_skeleton.rb:23
* high_and_low -> test_skeleton.rb:38
* my_languages -> test_skeleton.rb:51
* remove_array_elements -> test_skeleton.rb:64
* consecutive_duplicates -> test_skeleton.rb:74
* middle_chars -> test_skeleton.rb:92
54 changes: 54 additions & 0 deletions test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

require 'rspec/autorun'
require_relative './test_skeleton.rb'

describe TestSkeleton do
let(:suite) { TestSkeleton.new }

it 'Should return word even or odd due to number' do
expect(suite.even_or_odd(0)).to eq('even')
expect(suite.even_or_odd(121)).to eq('odd')
expect(suite.even_or_odd(-5)).to eq('odd')
expect(suite.even_or_odd(44)).to eq('even')
end

it 'Should return reversed array of digits' do
expect(suite.reverse_array(12)).to eq([2, 1])
expect(suite.reverse_array(5896)).to eq([6, 9, 8, 5])
expect(suite.reverse_array(0)).to eq([0])
expect(suite.reverse_array(62854)).to eq([4, 5, 8, 2, 6])
end

it 'Should return highest and lowest numbers from string' do
expect(suite.high_and_low('0 1 2 3 4 5')).to eq('5 0')
expect(suite.high_and_low('-3 -2 -1 0 1 2 3')).to eq('3 -3')
expect(suite.high_and_low('0')).to eq('0 0')
expect(suite.high_and_low('-3 -2 -1')).to eq('-1 -3')
end

it 'Should return languages where score more than 60' do
expect(suite.my_languages('Hindi' => 65, 'Greek' => 70, 'German' => 20)).to eq(%w[Hindi Greek])
expect(suite.my_languages({})).to eq([])
expect(suite.my_languages('A' => 30, 'B' => 50, 'C' => 25)).to eq([])
end

it 'Should return array of numbers that not in second array' do
expect(suite.remove_array_elements([1, 2], [1])).to eq([2])
expect(suite.remove_array_elements([1, 1, 2, 5, 3, 3], [1, 3])).to eq([2, 5])
expect(suite.remove_array_elements([1, 2, 3, 4, nil, nil], [1, 2, nil])).to eq([3, 4])
end

it 'Should return string where words not consecutive repeated' do
expect(suite.consecutive_duplicates('aa bb bb cc dd')).to eq('aa bb cc dd')
expect(suite.consecutive_duplicates('apple banana cherry')).to eq('apple banana cherry')
expect(suite.consecutive_duplicates('aaa aaa aaa bbb bbb bbb aaa aaa ccc ccc ddd')).to eq('aaa bbb aaa ccc ddd')
end

it 'Should return middle character(s) of string' do
expect(suite.middle_chars('A')).to eq('A')
expect(suite.middle_chars('Cherry')).to eq('r')
expect(suite.middle_chars('push')).to eq('us')
expect(suite.middle_chars('Do Androids Dream of Electric Sheep?')).to eq(' o')
end
end
95 changes: 95 additions & 0 deletions test_skeleton.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# frozen_string_literal: true

class TestSkeleton
# https://www.codewars.com/kata/53da3dbb4a5168369a0000fe
# Create a function that takes an integer as an argument and returns "Even"
# for even numbers or "Odd" for odd numbers.
# Example:
# TestSkeleton.new.even_or_odd(1) should return "odd"
# TestSkeleton.new.even_or_odd(2) should return "even"
# TestSkeleton.new.even_or_odd(0) should return "even"
# TestSkeleton.new.even_or_odd(-42) should return "even"
def even_or_odd(number)
# Your solution should be here
end

# https://www.codewars.com/kata/5583090cbe83f4fd8c000051
# Convert number to reversed array of digits
# Given a random non-negative number, you have to return the digits of this
# number within an array in reverse order.
# Examples:
# TestSkeleton.new.reverse_array(348597) should return [7,9,5,8,4,3]
# TestSkeleton.new.reverse_array(0) should return [0]
def reverse_array(number)
# Your solution should be here
end

# https://www.codewars.com/kata/554b4ac871d6813a03000035
# In this little assignment you are given a string of space separated numbers,
# and have to return the highest and lowest number.
# Examples:
# TestSkeleton.new.high_and_low("1 2 3 4 5") should return "5 1"
# TestSkeleton.new.high_and_low("1 2 -3 4 5") should return "5 -3"
# TestSkeleton.new.high_and_low("1 9 3 4 -5") should return "9 -5"
# Notes
# All numbers are valid Int32, no need to validate them.
# There will always be at least one number in the input string.
# Output string must be two numbers separated by a single space, and highest number is first.
def high_and_low(test_string)
# Your solution should be here
end

# https://www.codewars.com/kata/5b16490986b6d336c900007d
# You are given a dictionary/hash/object containing some languages and your test results in the
# given languages. Return the list of languages where your test score is at least 60,
# in descending order of the results.
# Note: the scores will always be unique (so no duplicate values)
# Examples:
# TestSkeleton.new.my_languages({"Java" => 10, "Ruby" => 80, "Python" => 65}) should return ["Ruby", "Python"]
# TestSkeleton.new.my_languages({"Hindi" => 60, "Dutch" => 93, "Greek" => 71}) should return ["Dutch", "Greek", "Hindi"]
# TestSkeleton.new.my_languages({"C++" => 50, "ASM" => 10, "Haskell" => 20}) should return []
def my_languages(hash)
# Your solution should be here
end

# https://www.codewars.com/kata/563089b9b7be03472d00002b
# Define a method/function that removes from a given array of integers all the values contained in a second array.
# Examples:
# integer_list = [1, 1, 2 ,3 ,1 ,2 ,3 ,4]
# values_list = [1, 3]
# TestSkeleton.new.remove_array_elements(integer_list, values_list) should return [2, 2, 4]
# integer_list = [1, 1, 2 ,3 ,1 ,2 ,3 ,4, 4, 3 ,5, 6, 7, 2, 8]
# values_list = [1, 3, 4, 2]
# TestSkeleton.new.remove_array_elements(integer_list, values_list) should return [5, 6 ,7 ,8]
def remove_array_elements(source_array, values_array)
# Your solution should be here
end

# https://www.codewars.com/kata/5b39e91ee7a2c103300018b3
# Your task is to remove all consecutive duplicate words from a string,
# leaving only first words entries. Words would be separated by space
# Examples:
# string = "alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta"
# TestSkeleton.new.consecutive_duplicates(string) should return "alpha beta gamma delta alpha beta gamma delta"
def consecutive_duplicates(string)
# Your solution should be here
end

# https://www.codewars.com/kata/56747fd5cb988479af000028
# You are going to be given a word. Your job is to return the middle character of the word.
# If the word's length is odd, return the middle character. If the word's length is even,
# return the middle 2 characters.
# Examples:
# TestSkeleton.new.middle_chars("test") should return "es"
# TestSkeleton.new.middle_chars("testing") should return "t"
# TestSkeleton.new.middle_chars("middle") should return "dd"
# TestSkeleton.new.middle_chars("A") should return "A"
# Input:
# A word (string) of length 0 < str < 1000
# You do not need to test for this.
# Output:
# The middle character(s) of the word represented as a string.
def middle_chars(test_string)
# Your solution should be here
end
end

0 comments on commit 52d8edd

Please sign in to comment.