Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f03ae4b
commit 8a6b7df
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# Table Class | ||
class Table | ||
attr_reader :x, :y | ||
|
||
def initialize(x = 5, y = 5) | ||
@x = x | ||
@y = y | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
require 'rspec' | ||
require 'spec_helper' | ||
require './lib/table' | ||
|
||
describe Table do | ||
describe '#initialize' do | ||
it 'should have an x attribute which is an integer' do | ||
instance = Table.new | ||
|
||
expect(instance.x).to be_a Integer | ||
expect(instance.x).to eq 5 | ||
end | ||
|
||
it 'should have a y attribute which is an integer' do | ||
instance = Table.new | ||
|
||
expect(instance.y).to be_a Integer | ||
expect(instance.y).to eq 5 | ||
end | ||
end | ||
|
||
describe '#valid_position?' do | ||
it 'should return true when x and y attributes are valid' do | ||
instance = Table.new | ||
|
||
expect(instance.valid_position?(0, 1)).to be true | ||
end | ||
|
||
it 'should return false when x and y attributes are too big' do | ||
instance = Table.new | ||
|
||
expect(instance.valid_position?(6, 6)).to be false | ||
end | ||
|
||
it 'should return false when x attribute is too big' do | ||
instance = Table.new | ||
|
||
expect(instance.valid_position?(6, 0)).to be false | ||
end | ||
|
||
it 'should return false when y attribute is too big' do | ||
instance = Table.new | ||
|
||
expect(instance.valid_position?(0, 6)).to be false | ||
end | ||
|
||
it 'should return false when x and y attributes are negative' do | ||
instance = Table.new | ||
|
||
expect(instance.valid_position?(-1, -1)).to be false | ||
end | ||
|
||
it 'should return false when x attribute is negative' do | ||
instance = Table.new | ||
|
||
expect(instance.valid_position?(-2, 0)).to be false | ||
end | ||
|
||
it 'should return false when y attribute is negative' do | ||
instance = Table.new | ||
|
||
expect(instance.valid_position?(0, -2)).to be false | ||
end | ||
end | ||
|
||
describe '#valid_x?' do | ||
it 'should return true when x is not greater than or equal to 0' do | ||
instance = Table.new | ||
|
||
expect(instance.send(:valid_x?, 0)).to be true | ||
end | ||
|
||
it 'should return true when x is less than or equal to 4' do | ||
instance = Table.new | ||
|
||
expect(instance.send(:valid_x?, 4)).to be true | ||
end | ||
|
||
it 'should return false when x is less 0' do | ||
instance = Table.new | ||
|
||
expect(instance.send(:valid_x?, -1)).to be false | ||
end | ||
|
||
it 'should return false when x greater than 4' do | ||
instance = Table.new | ||
|
||
expect(instance.send(:valid_x?, 6)).to be false | ||
end | ||
end | ||
|
||
describe '#valid_y?' do | ||
it 'should return true when y is not greater than or equal to 0' do | ||
instance = Table.new | ||
|
||
expect(instance.send(:valid_y?, 0)).to be true | ||
end | ||
|
||
it 'should return true when y is less than or equal to 4' do | ||
instance = Table.new | ||
|
||
expect(instance.send(:valid_y?, 4)).to be true | ||
end | ||
|
||
it 'should return false when y is less 0' do | ||
instance = Table.new | ||
|
||
expect(instance.send(:valid_y?, -1)).to be false | ||
end | ||
|
||
it 'should return false when y greater than 4' do | ||
instance = Table.new | ||
|
||
expect(instance.send(:valid_y?, 6)).to be false | ||
end | ||
end | ||
end |