ZobristHashTest.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include <boost/test/auto_unit_test.hpp>
00007
00008 #include "ZobristHash.hpp"
00009
00010 using namespace benzene;
00011
00012
00013
00014 namespace {
00015
00016 BOOST_AUTO_TEST_CASE(ZobristHash_InitializationAndUpdates)
00017 {
00018
00019
00020
00021
00022
00023
00024
00025
00026 ZobristHash zh1(5, 5);
00027 ZobristHash zh2(5, 5);
00028 BOOST_CHECK(zh1.Hash() == zh2.Hash());
00029
00030
00031 hash_t h1, h2, h3;
00032 h1 = zh1.Hash();
00033 zh1.Update(BLACK, FIRST_CELL);
00034 h2 = zh1.Hash();
00035 BOOST_CHECK(h1 != h2);
00036 zh1.Reset();
00037 BOOST_CHECK_EQUAL(h1, zh1.Hash());
00038 zh1.Update(WHITE, FIRST_CELL);
00039 h3 = zh1.Hash();
00040 BOOST_CHECK(h1 != h3);
00041 BOOST_CHECK(h2 != h3);
00042 zh1.Update(WHITE, FIRST_CELL);
00043 BOOST_CHECK_EQUAL(h1, zh1.Hash());
00044 zh1.Update(BLACK, FIRST_CELL);
00045 zh1.Update(WHITE, FIRST_CELL);
00046 BOOST_CHECK(h1 != zh1.Hash());
00047 BOOST_CHECK(h2 != zh1.Hash());
00048 BOOST_CHECK(h3 != zh1.Hash());
00049 zh1.Update(BLACK, FIRST_CELL);
00050 BOOST_CHECK_EQUAL(h3, zh1.Hash());
00051
00052
00053
00054 bitset_t black, white;
00055 BOOST_REQUIRE(FIRST_CELL < FIRST_INVALID - 1);
00056 black.set(FIRST_CELL);
00057 black.set(FIRST_INVALID - 1);
00058 white.set(SWAP_PIECES);
00059 zh1 = ZobristHash(5, 5);
00060 zh1.Compute(black, white);
00061 h1 = zh1.Hash();
00062 zh1.Reset();
00063 zh1.Update(BLACK, FIRST_CELL);
00064 BOOST_CHECK(h1 != zh1.Hash());
00065 zh1.Update(WHITE, SWAP_PIECES);
00066 BOOST_CHECK(h1 != zh1.Hash());
00067 zh1.Update(BLACK, static_cast<HexPoint>(FIRST_INVALID - 1));
00068 BOOST_CHECK_EQUAL(h1, zh1.Hash());
00069
00070
00071
00072 zh1.Reset();
00073 zh1.Compute(black, white);
00074 BOOST_CHECK_EQUAL(h1, zh1.Hash());
00075 zh1.Reset();
00076 for (int i=0; i<FIRST_INVALID; ++i) {
00077 if (black.test(i))
00078 zh1.Update(BLACK, static_cast<HexPoint>(i));
00079 if (white.test(i))
00080 zh1.Update(WHITE, static_cast<HexPoint>(i));
00081 }
00082 BOOST_CHECK_EQUAL(h1, zh1.Hash());
00083 }
00084
00085 }
00086
00087