From 19bd29f9b2a3e4721943496debfc55e2a7d71da5 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Thu, 31 Dec 2015 00:14:02 -0800 Subject: [PATCH 1/1] Promote Board to a class so it can have methods. --- sliding_tile_lib.cc | 2 +- sliding_tile_lib.h | 4 +++- sliding_tile_lib_test.cc | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) 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) { -- 2.44.1