2014-05-27 19:40:26 +00:00
|
|
|
require_relative '../features/support/language_screenshot'
|
|
|
|
|
|
|
|
# Rectangle is defined as set of co-ordinates represented by top left x, top left y, width, height
|
2014-11-21 16:06:09 +00:00
|
|
|
describe 'Rectangle' do
|
|
|
|
it 'should return the co-ordinates of provided 1 rectangle' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle = [0, 0, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle]
|
|
|
|
expect(rectangle(input_rectangles)).to eq(input_rectangle)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'should return the co-ordinates of the rectangle which is inside a iframe' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle = [50, 50, 10, 10]
|
|
|
|
iframe_rectangle = [100, 100, 20, 20]
|
2014-07-15 12:30:51 +00:00
|
|
|
input_rectangles = [input_rectangle]
|
|
|
|
output_rectangle = [150, 150, 10, 10]
|
|
|
|
expect(rectangle(input_rectangles, iframe_rectangle)).to eq(output_rectangle)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 2 rectangles and if one contains the other then it should return co-ordinates of bigger rectangle' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [0, 0, 1, 1]
|
|
|
|
input_rectangle_2 = [0, 0, 2, 2]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle_1, input_rectangle_2]
|
|
|
|
expect(rectangle(input_rectangles)).to eq(input_rectangle_2)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 2 rectangles it should return co-ordinates of third rectangle which contains both' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [0, 0, 1, 1]
|
|
|
|
input_rectangle_2 = [1, 0, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles_1 = [input_rectangle_1, input_rectangle_2]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_rectangle_1 = [0, 0, 2, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(rectangle(input_rectangles_1)).to eq(output_rectangle_1)
|
|
|
|
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_3 = [1, 1, 1, 1]
|
|
|
|
input_rectangle_4 = [3, 3, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles_2 = [input_rectangle_3, input_rectangle_4]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_rectangle_2 = [1, 1, 3, 3]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(rectangle(input_rectangles_2)).to eq(output_rectangle_2)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 3 rectangles it should return co-ordinates the rectangle which contains all the input rectangles' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [1, 1, 1, 1]
|
|
|
|
input_rectangle_2 = [2, 2, 1, 1]
|
|
|
|
input_rectangle_3 = [3, 3, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle_1, input_rectangle_2, input_rectangle_3]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_rectangle_1 = [1, 1, 3, 3]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(rectangle(input_rectangles)).to eq(output_rectangle_1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
describe 'Calculate topleft co-ordinates' do
|
2014-05-27 19:40:26 +00:00
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 1 rectangle then it should return top left co-ordinates of the input rectangle' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle = [2, 2, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_coordinates = [2, 2]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(top_left_x_y(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 2 rectangles then it should return top left co-ordinates of the biggest rectangle containing both rectangles' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [1, 0, 1, 1]
|
|
|
|
input_rectangle_2 = [0, 0, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle_1, input_rectangle_2]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_coordinates = [0, 0]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(top_left_x_y(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 3 rectangles then it should return top left co-ordinates of the biggest rectangle containing both rectangles' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [3, 3, 1, 1]
|
|
|
|
input_rectangle_2 = [2, 2, 1, 1]
|
|
|
|
input_rectangle_3 = [1, 1, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle_1, input_rectangle_2, input_rectangle_3]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_coordinates = [1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(top_left_x_y(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
describe 'Topleft co-ordinates x' do
|
2014-05-27 19:40:26 +00:00
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 1 rectangle then it should return array of top left x co-ordinate of the input rectangle' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle = [2, 2, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle]
|
|
|
|
output_coordinates = [2]
|
|
|
|
expect(top_left_x_coordinates(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 2 rectangles then it should return array top left x co-ordinates' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [0, 0, 1, 1]
|
|
|
|
input_rectangle_2 = [1, 0, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle_1, input_rectangle_2]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_coordinates = [0, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(top_left_x_coordinates(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 3 rectangles then it should return array of top left x co-ordinates' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [3, 3, 1, 1]
|
|
|
|
input_rectangle_2 = [2, 2, 1, 1]
|
|
|
|
input_rectangle_3 = [1, 1, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle_1, input_rectangle_2, input_rectangle_3]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_coordinates = [3, 2, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(top_left_x_coordinates(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
describe 'Topleft co-ordinates y' do
|
2014-05-27 19:40:26 +00:00
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 1 rectangle then it should return array of top left y co-ordinate of the input rectangle' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle = [2, 2, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle]
|
|
|
|
output_coordinates = [2]
|
|
|
|
expect(top_left_y_coordinates(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 2 rectangles then it should return array top left y co-ordinates' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [0, 0, 1, 1]
|
|
|
|
input_rectangle_2 = [1, 0, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle_1, input_rectangle_2]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_coordinates = [0, 0]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(top_left_y_coordinates(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 3 rectangles then it should return array of top left y co-ordinates' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [3, 3, 1, 1]
|
|
|
|
input_rectangle_2 = [2, 2, 1, 1]
|
|
|
|
input_rectangle_3 = [1, 1, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle_1, input_rectangle_2, input_rectangle_3]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_coordinates = [3, 2, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(top_left_y_coordinates(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
describe 'Calculate bottomright co-ordinates' do
|
2014-05-27 19:40:26 +00:00
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 1 rectangle then it should return bottom right co-ordinates of the input rectangle' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle = [2, 2, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_coordinates = [3, 3]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(bottom_right_x_y(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 2 rectangles then it should return bottom right co-ordinates of the biggest rectangle containing both rectangles' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [1, 0, 1, 1]
|
|
|
|
input_rectangle_2 = [0, 0, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle_1, input_rectangle_2]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_coordinates = [2, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(bottom_right_x_y(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 3 rectangles then it should return bottom right co-ordinates of the biggest rectangle containing both rectangles' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [3, 3, 1, 1]
|
|
|
|
input_rectangle_2 = [2, 2, 1, 1]
|
|
|
|
input_rectangle_3 = [1, 1, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle_1, input_rectangle_2, input_rectangle_3]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_coordinates = [4, 4]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(bottom_right_x_y(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
describe 'Bottom right co-ordinates x' do
|
2014-05-27 19:40:26 +00:00
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 1 rectangle then it should return array of bottom right x co-ordinate of the input rectangle' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle = [2, 2, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle]
|
|
|
|
output_coordinates = [3]
|
|
|
|
expect(bottom_right_x_coordinates(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 2 rectangles then it should return array bottom right x co-ordinates' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [0, 0, 1, 1]
|
|
|
|
input_rectangle_2 = [1, 0, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle_1, input_rectangle_2]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_coordinates = [1, 2]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(bottom_right_x_coordinates(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 3 rectangles then it should return array of bottom right x co-ordinates' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [3, 3, 1, 1]
|
|
|
|
input_rectangle_2 = [2, 2, 1, 1]
|
|
|
|
input_rectangle_3 = [1, 1, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle_1, input_rectangle_2, input_rectangle_3]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_coordinates = [4, 3, 2]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(bottom_right_x_coordinates(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
describe 'Bottom right co-ordinates y' do
|
2014-05-27 19:40:26 +00:00
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 1 rectangle then it should return array of bottom right y co-ordinate of the input rectangle' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle = [2, 2, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle]
|
|
|
|
output_coordinates = [3]
|
|
|
|
expect(bottom_right_y_coordinates(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 2 rectangles then it should return array bottom right y co-ordinates' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [0, 0, 1, 1]
|
|
|
|
input_rectangle_2 = [1, 0, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle_1, input_rectangle_2]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_coordinates = [1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(bottom_right_y_coordinates(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
2014-11-21 16:06:09 +00:00
|
|
|
it 'if we provide 3 rectangles then it should return array of bottom right y co-ordinates' do
|
2014-11-21 16:13:04 +00:00
|
|
|
input_rectangle_1 = [3, 3, 1, 1]
|
|
|
|
input_rectangle_2 = [2, 2, 1, 1]
|
|
|
|
input_rectangle_3 = [1, 1, 1, 1]
|
2014-05-27 19:40:26 +00:00
|
|
|
input_rectangles = [input_rectangle_1, input_rectangle_2, input_rectangle_3]
|
2014-11-21 16:13:04 +00:00
|
|
|
output_coordinates = [4, 3, 2]
|
2014-05-27 19:40:26 +00:00
|
|
|
expect(bottom_right_y_coordinates(input_rectangles)).to eq(output_coordinates)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|