Created
January 27, 2012 01:50
-
-
Save dpick/1686421 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/spec' | |
require 'minitest/autorun' | |
# Integer list generation | |
listOfInt = [1, 3, 5, 7, 9, 11] | |
left, right = 0, 1 | |
top, bottom = 2, 3 | |
def rotateFromRight(alist) | |
#Rotates alist so that the rightmost element appears at the left end of | |
#the list and the other elements are pushed toward the right end of the list | |
end | |
def rotateFromLeft(alist) | |
#Rotates alist so that the leftmost element appears at the right end of | |
#the list and the other elements are pushed toward the left end of the list | |
temp = alist[0] | |
(1..alist.size).each do |i| | |
alist[i - 1] = alist[i] | |
end | |
alist[alist.size - 1] = temp | |
return alist | |
end | |
def rotateRow(alist, side) | |
#Rotates alist from side where side == left or side == right | |
end | |
def rotateAnyRow(alist, row, side) | |
#Rotates a given row of atable from side where side == left or side == right. | |
#row is given as an integer value. atable is a list of list of elements | |
end | |
def rotateFromTop(alist, col = 0) | |
#Rotates a given column (col) of atable so that the topmost element | |
#appears at the bottom of the column and the other elements are pushed toward | |
#the top of the column. col is given as an integer value. atable is a list | |
#of list of elements. | |
end | |
def rotateFromBottom(alist, col = 0) | |
#Rotates a given column (col) of atable so that the bottommost element | |
#appears at the top of the column and the other elements are pushed toward | |
#the bottom of the column. col is given as an integer value. atable is a list | |
#of list of elements. | |
end | |
def rotateAnyColumn(alist, col, side) | |
#Rotates a given column (col) of atable from side where side == top or | |
#side == bottom. col is given as an integer value. atable is a list | |
#of list of elements. | |
end | |
def genListOfList() | |
#Generates a list of list of integers | |
[ [1, 3, 5, 7, 9, 11], | |
[5, 15, 25, 35, 45, 55], | |
[1, 9, 25, 49, 81, 121], | |
[-1, -3, -5, -7, -9, -11], | |
[2, 6, 10, 14, 18, 22], | |
[0, 1, 2, 3, 4, 5] ] | |
end | |
describe "Rotation Functions" do | |
before do | |
@list = [1, 3, 5, 7, 9, 11] | |
@list_of_lists = genListOfList | |
end | |
it 'is able to rotate a list left' do | |
rotateFromLeft(@list).must_equal [3, 5, 7, 9, 11, 1] | |
end | |
it 'is able to rotate a list right' do | |
rotateFromRight(@list).must_equal [11, 1, 3, 5, 7, 9] | |
end | |
it 'is able to rotate a row left' do | |
rotateRow(@list, left).must_equal [3, 5, 7, 9, 11, 1] | |
end | |
it 'is able to rotate a row right' do | |
rotateRow(@list, right).must_equal [11, 1, 3, 5, 7, 9] | |
end | |
it 'is able to rotate any row in a list of lists' do | |
rotateAnyRow(@list_of_lists, 5, right).must_equal [[1, 3, 5, 7, 9, 11], [5, 15, 25, 35, 45, 55], [1, 9, 25, 49, 81, 121], [-1, -3, -5, -7, -9, -11], [2, 6, 10, 14, 18, 22], [5, 0, 1, 2, 3, 4]] | |
end | |
it 'is able to rotate a column from the top to the bottom' do | |
rotateFromTop(@list_of_lists).must_equal [[5, 3, 5, 7, 9, 11], [1, 15, 25, 35, 45, 55], [-1, 9, 25, 49, 81, 121], [2, -3, -5, -7, -9, -11], [0, 6, 10, 14, 18, 22], [1, 1, 2, 3, 4, 5]] | |
end | |
it 'is able to rotate a column from the bottom to the top' do | |
rotateFromBottom(@list_of_lists).must_equal [[0, 3, 5, 7, 9, 11], [1, 15, 25, 35, 45, 55], [5, 9, 25, 49, 81, 121], [1, -3, -5, -7, -9, -11], [-1, 6, 10, 14, 18, 22], [2, 1, 2, 3, 4, 5]] | |
end | |
it 'is able to rotate any column' do | |
rotateAnyColumn(@list_of_lists, 0, top).must_equal [[1, 3, 5, 7, 9, 11], [5, 15, 25, 35, 45, 55], [1, 9, 25, 49, 81, 121], [-1, -3, -5, -7, -9, -11], [2, 6, 10, 14, 18, 22], [0, 1, 2, 3, 4, 5]] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment