|
| 1 | +require 'rspec' |
| 2 | +require 'spec_helper' |
| 3 | +require './lib/table' |
| 4 | + |
| 5 | +describe Table do |
| 6 | + describe '#initialize' do |
| 7 | + it 'should have an x attribute which is an integer' do |
| 8 | + instance = Table.new |
| 9 | + |
| 10 | + expect(instance.x).to be_a Integer |
| 11 | + expect(instance.x).to eq 5 |
| 12 | + end |
| 13 | + |
| 14 | + it 'should have a y attribute which is an integer' do |
| 15 | + instance = Table.new |
| 16 | + |
| 17 | + expect(instance.y).to be_a Integer |
| 18 | + expect(instance.y).to eq 5 |
| 19 | + end |
| 20 | + end |
| 21 | + |
| 22 | + describe '#valid_position?' do |
| 23 | + it 'should return true when x and y attributes are valid' do |
| 24 | + instance = Table.new |
| 25 | + |
| 26 | + expect(instance.valid_position?(0, 1)).to be true |
| 27 | + end |
| 28 | + |
| 29 | + it 'should return false when x and y attributes are too big' do |
| 30 | + instance = Table.new |
| 31 | + |
| 32 | + expect(instance.valid_position?(6, 6)).to be false |
| 33 | + end |
| 34 | + |
| 35 | + it 'should return false when x attribute is too big' do |
| 36 | + instance = Table.new |
| 37 | + |
| 38 | + expect(instance.valid_position?(6, 0)).to be false |
| 39 | + end |
| 40 | + |
| 41 | + it 'should return false when y attribute is too big' do |
| 42 | + instance = Table.new |
| 43 | + |
| 44 | + expect(instance.valid_position?(0, 6)).to be false |
| 45 | + end |
| 46 | + |
| 47 | + it 'should return false when x and y attributes are negative' do |
| 48 | + instance = Table.new |
| 49 | + |
| 50 | + expect(instance.valid_position?(-1, -1)).to be false |
| 51 | + end |
| 52 | + |
| 53 | + it 'should return false when x attribute is negative' do |
| 54 | + instance = Table.new |
| 55 | + |
| 56 | + expect(instance.valid_position?(-2, 0)).to be false |
| 57 | + end |
| 58 | + |
| 59 | + it 'should return false when y attribute is negative' do |
| 60 | + instance = Table.new |
| 61 | + |
| 62 | + expect(instance.valid_position?(0, -2)).to be false |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + describe '#valid_x?' do |
| 67 | + it 'should return true when x is not greater than or equal to 0' do |
| 68 | + instance = Table.new |
| 69 | + |
| 70 | + expect(instance.send(:valid_x?, 0)).to be true |
| 71 | + end |
| 72 | + |
| 73 | + it 'should return true when x is less than or equal to 4' do |
| 74 | + instance = Table.new |
| 75 | + |
| 76 | + expect(instance.send(:valid_x?, 4)).to be true |
| 77 | + end |
| 78 | + |
| 79 | + it 'should return false when x is less 0' do |
| 80 | + instance = Table.new |
| 81 | + |
| 82 | + expect(instance.send(:valid_x?, -1)).to be false |
| 83 | + end |
| 84 | + |
| 85 | + it 'should return false when x greater than 4' do |
| 86 | + instance = Table.new |
| 87 | + |
| 88 | + expect(instance.send(:valid_x?, 6)).to be false |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + describe '#valid_y?' do |
| 93 | + it 'should return true when y is not greater than or equal to 0' do |
| 94 | + instance = Table.new |
| 95 | + |
| 96 | + expect(instance.send(:valid_y?, 0)).to be true |
| 97 | + end |
| 98 | + |
| 99 | + it 'should return true when y is less than or equal to 4' do |
| 100 | + instance = Table.new |
| 101 | + |
| 102 | + expect(instance.send(:valid_y?, 4)).to be true |
| 103 | + end |
| 104 | + |
| 105 | + it 'should return false when y is less 0' do |
| 106 | + instance = Table.new |
| 107 | + |
| 108 | + expect(instance.send(:valid_y?, -1)).to be false |
| 109 | + end |
| 110 | + |
| 111 | + it 'should return false when y greater than 4' do |
| 112 | + instance = Table.new |
| 113 | + |
| 114 | + expect(instance.send(:valid_y?, 6)).to be false |
| 115 | + end |
| 116 | + end |
| 117 | +end |
0 commit comments