KarthickNarayana / toy_robot

0 stars 0 forks source link

Where compound conditionals exist, test all cases independently #23

Open scepticalcat opened 3 years ago

scepticalcat commented 3 years ago

https://github.com/KarthickNarayana/toy_robot/blob/3d570a92d5c8b027e2456ec4f7bce47223719ecf/spec/toy_robot/tabletop_spec.rb#L10

The bug mentioned previously in an earlier comment where the horizontal position is never effectively validated could have been caught if the tests here independently tested each of the conditions instead of combining them, eg.

describe "#valid_loc?" do
  subject { ToyRobot::TableTop.new columns, rows }

  let(:columns) { a_number }
  let(:rows)    { a_number }

  context "when the horizontal position is < 0" do
    it "is false" do
      expect(subject.valid_loc?(-1, 0)).to be false
    end
  end

  context "when the horizontal position is > columns" do
    it "is false" do
      expect(subject.valid_loc?(columns + 1, 0)).to be false
    end
  end

  ...

  context "when both horizontal and vertical positions are valid" do
    it "is true" do
      expect(subject.valid_loc?(0, 0)).to be true
    end
  end
end
KarthickNarayana commented 3 years ago

agreed ..