Skip to content

Instantly share code, notes, and snippets.

@JEG2
Created September 23, 2010 04:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JEG2/593069 to your computer and use it in GitHub Desktop.
Save JEG2/593069 to your computer and use it in GitHub Desktop.
I wish all of these satisfy calls weren't needed to pass warnings
require "go/gtp/board"
describe Go::GTP::Board do
before :all do
@string = <<-END_BOARD.gsub(/^ {4}/, "")
A B C D E F G H J
9 . . . . . . . . . 9
8 . . . . . . . . . 8
7 . . X . . . + . . 7
6 . . . . . . . . . 6
5 . . . . + . . . . 5
4 . . . . . . . . . 4
3 . . + . . O + . . 3
2 . . . . . . . . . 2 WHITE (O) has captured 10 stones
1 . . . . . . . . . 1 BLACK (X) has captured 11 stones
A B C D E F G H J
END_BOARD
@board = Go::GTP::Board.new(@string)
end
it "should stringify to what it was created from" do
@board.to_s.should == @string
end
it "should support indexing by coordinates" do
@board[0, 0].should be_nil
@board[2, 6].should satisfy { |color| color == "black" }
@board[5, 2].should satisfy { |color| color == "white" }
end
it "should support indexing by vertices" do
@board["A1"].should be_nil
@board["C7"].should satisfy { |color| color == "black" }
@board["F3"].should satisfy { |color| color == "white" }
end
it "should fail to index for any other combination" do
lambda { @board["A", "1"] }.should raise_error(ArgumentError)
end
it "should be able to count captures by color name" do
@board.captures("white").should satisfy { |stones| stones == 10 }
@board.captures("WHITE").should satisfy { |stones| stones == 10 }
@board.captures("black").should satisfy { |stones| stones == 11 }
@board.captures("BLACK").should satisfy { |stones| stones == 11 }
end
it "should be able to count captures by stone type" do
@board.captures("o").should satisfy { |stones| stones == 10 }
@board.captures("O").should satisfy { |stones| stones == 10 }
@board.captures("x").should satisfy { |stones| stones == 11 }
@board.captures("X").should satisfy { |stones| stones == 11 }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment