learn-co-curriculum / oo-tic-tac-toe

Other
4 stars 641 forks source link

positions as ints then strings then 0-based then 1-based...why? #25

Closed mennamorato closed 7 years ago

mennamorato commented 8 years ago

Ok maybe I'm confused but the spec is using "position" as integers for some checks, strings for other checks, is sometimes based on 0..8 and other times 1..9. What is going on here? eg: see below describe '#position_taken?' do it 'returns true/false based on position in board' do game = TicTacToe.new board = ["X", " ", " ", " ", " ", " ", " ", " ", "O"] game.instance_variable_set(:@board, board)

    position = 0
    expect(game.position_taken?(position)).to be(true)

    position = 8
    expect(game.position_taken?(position)).to be(true)

    position = 1
    expect(game.position_taken?(position)).to be(false)

    position = 7
    expect(game.position_taken?(position)).to be(false)
  end
end

describe '#valid_move?' do
  it 'returns true/false based on position' do
    game = TicTacToe.new
    board = [" ", " ", " ", " ", "X", " ", " ", " ", " "]
    game.instance_variable_set(:@board, board)

    position = "1"
    expect(game.valid_move?(position)).to be_truthy

    position = "5"
    expect(game.valid_move?(position)).to be_falsey

    position = "invalid"
    expect(game.valid_move?(position)).to be_falsey
  end
end
aturkewi commented 7 years ago

Made consistent in PR #33