00001 //---------------------------------------------------------------------------- 00002 /** @file GraphUtilsTest.cpp 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #include <boost/test/auto_unit_test.hpp> 00007 00008 #include "GraphUtils.hpp" 00009 00010 using namespace benzene; 00011 00012 //--------------------------------------------------------------------------- 00013 00014 namespace { 00015 00016 BOOST_AUTO_TEST_CASE(GraphUtils_ComputeDigraph) 00017 { 00018 BOOST_REQUIRE(MAX_WIDTH >= 5 && MAX_HEIGHT >= 5); 00019 StoneBoard gb(5, 5); 00020 gb.StartNewGame(); 00021 00022 // a b c d e 00023 // 1\. . . . .\1 00024 // 2\W B . . .\2 00025 // 3\. B . . .\3 00026 // 4\. . . . .\4 00027 // 5\. . . . .\5 00028 // a b c d e 00029 HexPoint a1 = HEX_CELL_A1; 00030 HexPoint b1 = HEX_CELL_B1; 00031 HexPoint c1 = HEX_CELL_C1; 00032 HexPoint a2 = HEX_CELL_A2; 00033 HexPoint b2 = HEX_CELL_B2; 00034 HexPoint c2 = HEX_CELL_C2; 00035 HexPoint a3 = HEX_CELL_A3; 00036 HexPoint b3 = HEX_CELL_B3; 00037 HexPoint c3 = HEX_CELL_C3; 00038 HexPoint a4 = HEX_CELL_A4; 00039 HexPoint b4 = HEX_CELL_B4; 00040 HexPoint a5 = HEX_CELL_A5; 00041 00042 bitset_t nbs; 00043 gb.PlayMove(BLACK, b2); 00044 gb.PlayMove(WHITE, a2); 00045 gb.PlayMove(BLACK, b3); 00046 Groups groups; 00047 GroupBuilder::Build(gb, groups); 00048 00049 PointToBitset dg; 00050 GraphUtils::ComputeDigraph(groups, BLACK, dg); 00051 00052 BOOST_CHECK(dg[groups.CaptainOf(b2)] == groups.Nbs(b2, EMPTY)); 00053 00054 BOOST_CHECK_EQUAL(dg[a3].count(), 6u); 00055 BOOST_CHECK(dg[a3].test(b1)); 00056 BOOST_CHECK(dg[a3].test(c1)); 00057 BOOST_CHECK(dg[a3].test(c2)); 00058 BOOST_CHECK(dg[a3].test(c3)); 00059 BOOST_CHECK(dg[a3].test(a4)); 00060 BOOST_CHECK(dg[a3].test(b4)); 00061 00062 GraphUtils::ComputeDigraph(groups, WHITE, dg); 00063 00064 BOOST_CHECK(dg[groups.CaptainOf(a2)] == groups.Nbs(a2, EMPTY)); 00065 00066 BOOST_CHECK(dg[groups.CaptainOf(c3)] == groups.Nbs(c3, EMPTY)); 00067 00068 BOOST_CHECK_EQUAL(dg[b1].count(), 5u); 00069 BOOST_CHECK(dg[b1].test(a1)); 00070 BOOST_CHECK(dg[b1].test(c1)); 00071 BOOST_CHECK(dg[b1].test(a3)); 00072 BOOST_CHECK(dg[b1].test(a4)); 00073 BOOST_CHECK(dg[b1].test(a5)); 00074 } 00075 00076 } 00077 00078 //---------------------------------------------------------------------------