Skip to content

Instantly share code, notes, and snippets.

@soveran
Created September 23, 2010 15:03
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 soveran/593761 to your computer and use it in GitHub Desktop.
Save soveran/593761 to your computer and use it in GitHub Desktop.
require "go/gtp/board"
require "cutest"
setup do
string = <<-EOS.gsub(/^ {2}/, "")
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
EOS
[Go::GTP::Board.new(string), string]
end
test "should stringify to what it was created from" do |board, string|
assert board.to_s == string
end
test "should support indexing by coordinates" do |board|
assert board[0, 0].nil?
assert board[2, 6] == "black"
assert board[5, 2] == "white"
end
test "should support indexing by vertices" do |board|
assert board["A1"].nil?
assert board["C7"] == "black"
assert board["F3"] == "white"
end
test "should fail to index for any other combination" do |board|
assert_raise(ArgumentError) do
board["A", "1"]
end
end
test "should be able to count captures by color name" do |board|
assert board.captures("white") == 10
assert board.captures("WHITE") == 10
assert board.captures("black") == 11
assert board.captures("BLACK") == 11
end
test "should be able to count captures by stone type" do |board|
assert board.captures("o") == 10
assert board.captures("O") == 10
assert board.captures("x") == 11
assert board.captures("X") == 11
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment