]>
git.scottworley.com Git - slidingtile/blob - sliding_tile_lib_test.cc
12cc46b8a051394b03d7fd93b7d724a25917c92c
1 #include "sliding_tile_lib.h"
3 #include "gtest/gtest.h"
4 #include "gmock/gmock.h"
7 TEST(Adjacency
, Adjacency
) {
8 const signed char LEFT
= -1;
9 const signed char RIGHT
= +1;
10 const signed char UP
= -BOARD_DIM
;
11 const signed char DOWN
= +BOARD_DIM
;
12 for (int i
= 0; i
< BOARD_SIZE
; i
++) {
14 std::vector
<signed char> expected
;
16 expected
.push_back(i
+ UP
);
18 if (i
< BOARD_SIZE
- BOARD_DIM
) {
19 expected
.push_back(i
+ DOWN
);
21 if (i
% BOARD_DIM
!= 0) {
22 expected
.push_back(i
+ LEFT
);
24 if (i
% BOARD_DIM
!= BOARD_DIM
- 1) {
25 expected
.push_back(i
+ RIGHT
);
28 std::vector
<signed char> actual
;
29 for (int j
= 0; adjacent
[i
][j
] >= 0; j
++) {
30 actual
.push_back(adjacent
[i
][j
]);
32 EXPECT_THAT(actual
, testing::UnorderedElementsAreArray(expected
));
36 TEST(Board
, GoodInput
) {
37 std::istringstream is
{"15,14,9,13,3,1,12,8,0,11,6,4,7,5,2,10"};
40 EXPECT_FALSE(is
.fail());
41 EXPECT_TRUE(is
.eof());
42 EXPECT_THAT(b
.board
, testing::ElementsAreArray({15,14,9,13,3,1,12,8,0,11,6,4,7,5,2,10}));
45 TEST(Board
, ShortInput
) {
46 std::istringstream is
{"15,14,9,13,3,1,12,8,0,11,6,4,7,5,2"};
49 EXPECT_TRUE(is
.fail());
52 TEST(Board
, NonNumericInput
) {
53 std::istringstream is
{"15,14,foo,13,3,1,12,8,0,11,6,4,7,5,2,10"};
56 EXPECT_TRUE(is
.fail());
59 TEST(Board
, RepeatedTileInput
) {
60 std::istringstream is
{"15,15,9,13,3,1,12,8,0,11,6,4,7,5,2,10"};
63 EXPECT_TRUE(is
.fail());
66 TEST(Board
, LowTileInput
) {
67 std::istringstream is
{"-1,14,9,13,3,1,12,8,0,11,6,4,7,5,2,10"};
70 EXPECT_TRUE(is
.fail());
73 TEST(Board
, HighTileInput
) {
74 std::istringstream is
{"16,14,9,13,3,1,12,8,0,11,6,4,7,5,2,10"};
77 EXPECT_TRUE(is
.fail());
81 Board b
{{16,14,9,13,3,1,12,8,0,11,6,4,7,5,2,10}};
82 EXPECT_EQ(8, b
.hole());
86 Board b
{{16,14,9,13,3,1,12,8,16,11,6,4,7,5,2,10}};
87 EXPECT_THROW(b
.hole(), std::runtime_error
);