]> git.scottworley.com Git - slidingtile/blob - sliding_tile_lib_test.cc
"make depend" for tests too
[slidingtile] / sliding_tile_lib_test.cc
1 #include "sliding_tile_lib.h"
2
3 #include "gtest/gtest.h"
4 #include "gmock/gmock.h"
5 #include <vector>
6
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++) {
13 SCOPED_TRACE(i);
14 std::vector<signed char> expected;
15 if (i >= BOARD_DIM) {
16 expected.push_back(i + UP);
17 }
18 if (i < BOARD_SIZE - BOARD_DIM) {
19 expected.push_back(i + DOWN);
20 }
21 if (i % BOARD_DIM != 0) {
22 expected.push_back(i + LEFT);
23 }
24 if (i % BOARD_DIM != BOARD_DIM - 1) {
25 expected.push_back(i + RIGHT);
26 }
27
28 std::vector<signed char> actual;
29 for (int j = 0; adjacent[i][j] >= 0; j++) {
30 actual.push_back(adjacent[i][j]);
31 }
32 EXPECT_THAT(actual, testing::UnorderedElementsAreArray(expected));
33 }
34 }