Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

HexPointTest.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 /** @file HexPointTest.cpp
00003  */
00004 //---------------------------------------------------------------------------
00005 
00006 #include <boost/test/auto_unit_test.hpp>
00007 
00008 #include "Hex.hpp"
00009 
00010 using namespace benzene;
00011 
00012 //---------------------------------------------------------------------------
00013 
00014 namespace {
00015 
00016 BOOST_AUTO_TEST_CASE(HexPoint_NecessaryPointOrdering)
00017 {
00018     BOOST_CHECK(!INVALID_POINT);
00019     BOOST_CHECK(FIRST_SPECIAL < FIRST_EDGE);
00020     BOOST_CHECK(RESIGN < FIRST_EDGE);
00021     BOOST_CHECK(SWAP_PIECES < FIRST_EDGE);
00022     BOOST_CHECK(FIRST_EDGE < FIRST_CELL);
00023     BOOST_CHECK(NORTH < FIRST_CELL);
00024     BOOST_CHECK(SOUTH < FIRST_CELL);
00025     BOOST_CHECK(EAST < FIRST_CELL);
00026     BOOST_CHECK(WEST < FIRST_CELL);
00027     BOOST_CHECK(FIRST_CELL < FIRST_INVALID);
00028     BOOST_CHECK(FIRST_INVALID <= BITSETSIZE);
00029 }
00030 
00031 BOOST_AUTO_TEST_CASE(HexPoint_StringConversion)
00032 {
00033     BOOST_CHECK_EQUAL(HexPointUtil::ToString(INVALID_POINT), "invalid");
00034     BOOST_CHECK_EQUAL(HexPointUtil::ToString(RESIGN), "resign");
00035     BOOST_CHECK_EQUAL(HexPointUtil::ToString(SWAP_PIECES), "swap-pieces");
00036     BOOST_CHECK_EQUAL(HexPointUtil::ToString(NORTH), "north");
00037     BOOST_CHECK_EQUAL(HexPointUtil::ToString(SOUTH), "south");
00038     BOOST_CHECK_EQUAL(HexPointUtil::ToString(EAST), "east");
00039     BOOST_CHECK_EQUAL(HexPointUtil::ToString(WEST), "west");
00040     BOOST_CHECK_EQUAL(HexPointUtil::ToString(FIRST_CELL), "a1");
00041 
00042     // a smattering to ensure the constants a sync'd with the
00043     // strings in HexPointInit().
00044     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_A1),  "a1");
00045     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_A2),  "a2");
00046     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_A3),  "a3");
00047     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_A4),  "a4");
00048     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_A5),  "a5");
00049     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_A6),  "a6");
00050     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_A7),  "a7");
00051     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_A8),  "a8");
00052     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_A9),  "a9");
00053     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_A10), "a10");
00054     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_A11), "a11");
00055     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_B1),  "b1");
00056     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_C1),  "c1");
00057     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_C5),  "c5");
00058     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_D1),  "d1");
00059     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_F7),  "f7");
00060     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_I1),  "i1");
00061     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_K1),  "k1");
00062     BOOST_CHECK_EQUAL(HexPointUtil::ToString(HEX_CELL_K11), "k11");
00063     
00064     
00065     BOOST_CHECK_EQUAL(HexPointUtil::FromString("invalid"), INVALID_POINT);
00066     BOOST_CHECK_EQUAL(HexPointUtil::FromString("resign"), RESIGN);
00067     BOOST_CHECK_EQUAL(HexPointUtil::FromString("swap-pieces"), SWAP_PIECES);
00068     BOOST_CHECK_EQUAL(HexPointUtil::FromString("north"), NORTH);
00069     BOOST_CHECK_EQUAL(HexPointUtil::FromString("south"), SOUTH);
00070     BOOST_CHECK_EQUAL(HexPointUtil::FromString("east"), EAST);
00071     BOOST_CHECK_EQUAL(HexPointUtil::FromString("west"), WEST);
00072     BOOST_CHECK_EQUAL(HexPointUtil::FromString("a1"), FIRST_CELL);
00073     
00074     BOOST_CHECK_EQUAL(HexPointUtil::FromString
00075                       (HexPointUtil::ToString(HEX_CELL_E7)), 
00076                       HEX_CELL_E7);
00077 }
00078 
00079 BOOST_AUTO_TEST_CASE(HexPoint_StringConversionSequence)
00080 {
00081     std::string blah = "  a1  a2 a3 a4   a5\ta6 a7\n";
00082     PointSequence pts;
00083     HexPointUtil::FromString(blah, pts);
00084     BOOST_CHECK_EQUAL(pts.size(), 7u);
00085     BOOST_CHECK_EQUAL(pts[0], HEX_CELL_A1);
00086     BOOST_CHECK_EQUAL(pts[1], HEX_CELL_A2);
00087     BOOST_CHECK_EQUAL(pts[2], HEX_CELL_A3);
00088     BOOST_CHECK_EQUAL(pts[3], HEX_CELL_A4);
00089     BOOST_CHECK_EQUAL(pts[4], HEX_CELL_A5);
00090     BOOST_CHECK_EQUAL(pts[5], HEX_CELL_A6);
00091     BOOST_CHECK_EQUAL(pts[6], HEX_CELL_A7);
00092 }
00093 
00094 BOOST_AUTO_TEST_CASE(HexPoint_Swap)
00095 {
00096     BOOST_CHECK(!HexPointUtil::isSwap(INVALID_POINT));
00097     BOOST_CHECK(!HexPointUtil::isSwap(RESIGN));
00098     BOOST_CHECK( HexPointUtil::isSwap(SWAP_PIECES));
00099     BOOST_CHECK(!HexPointUtil::isSwap(FIRST_EDGE));
00100     BOOST_CHECK(!HexPointUtil::isSwap(FIRST_INVALID));
00101 }
00102 
00103 BOOST_AUTO_TEST_CASE(HexPoint_Edges)
00104 {
00105     BOOST_CHECK(!HexPointUtil::isEdge(INVALID_POINT));
00106     BOOST_CHECK(!HexPointUtil::isEdge(RESIGN));
00107     BOOST_CHECK(!HexPointUtil::isEdge(SWAP_PIECES));
00108     BOOST_CHECK( HexPointUtil::isEdge(FIRST_EDGE));
00109     BOOST_CHECK(!HexPointUtil::isEdge(FIRST_INVALID));
00110     BOOST_CHECK( HexPointUtil::isEdge(NORTH));
00111     BOOST_CHECK( HexPointUtil::isEdge(SOUTH));
00112     BOOST_CHECK( HexPointUtil::isEdge(WEST));
00113     BOOST_CHECK( HexPointUtil::isEdge(EAST));
00114     
00115     BOOST_CHECK_EQUAL(HexPointUtil::oppositeEdge(EAST), WEST);
00116     BOOST_CHECK_EQUAL(HexPointUtil::oppositeEdge(WEST), EAST);
00117     BOOST_CHECK_EQUAL(HexPointUtil::oppositeEdge(NORTH), SOUTH);
00118     BOOST_CHECK_EQUAL(HexPointUtil::oppositeEdge(SOUTH), NORTH);
00119     
00120     BOOST_CHECK_EQUAL(HexPointUtil::leftEdge(EAST), HexPointUtil::rightEdge(WEST));
00121     BOOST_CHECK_EQUAL(HexPointUtil::rightEdge(EAST), HexPointUtil::leftEdge(WEST));
00122     BOOST_CHECK_EQUAL(HexPointUtil::leftEdge(HexPointUtil::leftEdge(EAST)), WEST);
00123     BOOST_CHECK_EQUAL(HexPointUtil::leftEdge(SOUTH), WEST);
00124     BOOST_CHECK_EQUAL(HexPointUtil::rightEdge(SOUTH), EAST);
00125     BOOST_CHECK_EQUAL(HexPointUtil::rightEdge(NORTH), WEST);
00126     
00127     BOOST_CHECK_EQUAL(HexPointUtil::oppositeEdge(HexPointUtil::colorEdge1(BLACK)),
00128               HexPointUtil::colorEdge2(BLACK));
00129     BOOST_CHECK_EQUAL(HexPointUtil::oppositeEdge(HexPointUtil::colorEdge1(WHITE)),
00130               HexPointUtil::colorEdge2(WHITE));
00131     
00132     BOOST_CHECK(HexPointUtil::isColorEdge(NORTH, BLACK));
00133     BOOST_CHECK(HexPointUtil::isColorEdge(EAST, WHITE));
00134     BOOST_CHECK(HexPointUtil::isColorEdge(HexPointUtil::rightEdge
00135                       (HexPointUtil::colorEdge2(BLACK)), WHITE));
00136     BOOST_CHECK(HexPointUtil::isColorEdge(HexPointUtil::colorEdge1(BLACK), BLACK));
00137     BOOST_CHECK(HexPointUtil::isColorEdge(HexPointUtil::colorEdge2(BLACK), BLACK));
00138     BOOST_CHECK(HexPointUtil::isColorEdge(HexPointUtil::colorEdge1(WHITE), WHITE));
00139     BOOST_CHECK(HexPointUtil::isColorEdge(HexPointUtil::colorEdge2(WHITE), WHITE));
00140 }
00141 
00142 BOOST_AUTO_TEST_CASE(HexPoint_CoordsConversion)
00143 {
00144     int x, y;
00145     HexPointUtil::pointToCoords(FIRST_CELL, x, y);
00146     BOOST_CHECK_EQUAL(x, 0);
00147     BOOST_CHECK_EQUAL(y, 0);
00148     BOOST_CHECK_EQUAL(HexPointUtil::coordsToPoint(x, y), FIRST_CELL);
00149 
00150     HexPointUtil::pointToCoords(HEX_CELL_K11, x, y);
00151     BOOST_CHECK_EQUAL(x, MAX_WIDTH - 1);
00152     BOOST_CHECK_EQUAL(y, MAX_HEIGHT - 1);
00153     BOOST_CHECK_EQUAL(HexPointUtil::coordsToPoint(x, y), HEX_CELL_K11);
00154     
00155     BOOST_REQUIRE(MAX_WIDTH >= 2 && MAX_HEIGHT >= 2);
00156     BOOST_CHECK_EQUAL(HexPointUtil::coordsToPoint(0, 1), HEX_CELL_A2);
00157     BOOST_CHECK_EQUAL(HexPointUtil::coordsToPoint(1, 0), HEX_CELL_B1);
00158     BOOST_CHECK_EQUAL(HexPointUtil::coordsToPoint(1, 1), HEX_CELL_B2);
00159 }
00160 
00161 BOOST_AUTO_TEST_CASE(HexPoint_DirectionalDeltaXY)
00162 {
00163     BOOST_CHECK_EQUAL(HexPointUtil::DeltaX(DIR_EAST), 1);
00164     BOOST_CHECK_EQUAL(HexPointUtil::DeltaY(DIR_EAST), 0);
00165     BOOST_CHECK_EQUAL(HexPointUtil::DeltaX(DIR_NORTH_EAST), 1);
00166     BOOST_CHECK_EQUAL(HexPointUtil::DeltaY(DIR_NORTH_EAST), -1);
00167     BOOST_CHECK_EQUAL(HexPointUtil::DeltaX(DIR_NORTH), 0);
00168     BOOST_CHECK_EQUAL(HexPointUtil::DeltaY(DIR_NORTH), -1);
00169     BOOST_CHECK_EQUAL(HexPointUtil::DeltaX(DIR_WEST), -1);
00170     BOOST_CHECK_EQUAL(HexPointUtil::DeltaY(DIR_WEST), 0);
00171     BOOST_CHECK_EQUAL(HexPointUtil::DeltaX(DIR_SOUTH_WEST), -1);
00172     BOOST_CHECK_EQUAL(HexPointUtil::DeltaY(DIR_SOUTH_WEST), 1);
00173     BOOST_CHECK_EQUAL(HexPointUtil::DeltaX(DIR_SOUTH), 0);
00174     BOOST_CHECK_EQUAL(HexPointUtil::DeltaY(DIR_SOUTH), 1);
00175 }
00176 
00177 }
00178 
00179 //---------------------------------------------------------------------------


6 Jan 2011 Doxygen 1.6.3