From: Scott Worley Date: Thu, 31 Dec 2015 08:14:02 +0000 (-0800) Subject: Promote Board to a class so it can have methods. X-Git-Url: http://git.scottworley.com/slidingtile/commitdiff_plain/19bd29f9b2a3e4721943496debfc55e2a7d71da5?ds=sidebyside;hp=32688d85f745574d7bbf941985234458d2776cce Promote Board to a class so it can have methods. --- diff --git a/sliding_tile_lib.cc b/sliding_tile_lib.cc index a4d522e..24642f1 100644 --- a/sliding_tile_lib.cc +++ b/sliding_tile_lib.cc @@ -33,7 +33,7 @@ std::istream& operator>>(std::istream& is, Board& board) { } int numeric; is >> numeric; - board[i] = numeric; + board.board[i] = numeric; } return is; } diff --git a/sliding_tile_lib.h b/sliding_tile_lib.h index 8967324..1ffe6fa 100644 --- a/sliding_tile_lib.h +++ b/sliding_tile_lib.h @@ -6,7 +6,9 @@ const int BOARD_DIM = 4; const int BOARD_SIZE = BOARD_DIM * BOARD_DIM; -typedef signed char Board[BOARD_SIZE]; +struct Board { + signed char board[BOARD_SIZE]; +}; std::istream& operator>>(std::istream& is, Board& board); extern signed char adjacent[BOARD_SIZE][5]; diff --git a/sliding_tile_lib_test.cc b/sliding_tile_lib_test.cc index 0bbaec3..a0a6b52 100644 --- a/sliding_tile_lib_test.cc +++ b/sliding_tile_lib_test.cc @@ -39,7 +39,7 @@ TEST(Board, GoodInput) { is >> b; EXPECT_FALSE(is.fail()); EXPECT_TRUE(is.eof()); - EXPECT_THAT(b, testing::ElementsAreArray({15,14,9,13,3,1,12,8,0,11,6,4,7,5,2,10})); + EXPECT_THAT(b.board, testing::ElementsAreArray({15,14,9,13,3,1,12,8,0,11,6,4,7,5,2,10})); } TEST(Board, ShortInput) {