Skip to content

Commit

Permalink
Add table spec
Browse files Browse the repository at this point in the history
  • Loading branch information
SelenaSmall committed Aug 26, 2017
1 parent f03ae4b commit 8a6b7df
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/table.rb
@@ -1,5 +1,7 @@
# Table Class
class Table
attr_reader :x, :y

def initialize(x = 5, y = 5)
@x = x
@y = y
Expand Down
117 changes: 117 additions & 0 deletions spec/table_spec.rb
@@ -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

0 comments on commit 8a6b7df

Please sign in to comment.