Debian Codegraph @

old-sample/legacy-checkmate/test/checkHashRecord.t.cc

raw
1 /* checkHashRecordTest.cc
2 */
3 #include "osl/checkmate/checkHashRecord.h"
4
5 #include <cppunit/TestCase.h>
6 #include <cppunit/extensions/HelperMacros.h>
7 #include <iostream>
8
9 class checkHashRecordTest : public CppUnit::TestFixture
10 {
11 CPPUNIT_TEST_SUITE(checkHashRecordTest);
12 CPPUNIT_TEST(testSize);
13 CPPUNIT_TEST(testTwins);
14 CPPUNIT_TEST(testFindDagOrigin);
15 CPPUNIT_TEST_SUITE_END();
16 public:
17 void testTwins();
18 void testSize();
19 void testFindDagOrigin();
20 };
21 CPPUNIT_TEST_SUITE_REGISTRATION(checkHashRecordTest);
22
23 using namespace osl;
24 using namespace osl::checkmate;
25
26 void checkHashRecordTest::testTwins()
27 {
28 CheckHashRecord record;
29 PathEncoding pathBefore(BLACK);
30 CheckMove move(Move(Square(7,3),GOLD,BLACK), &record);
31 PathEncoding pathAfter = pathBefore;
32 pathAfter.pushMove(move.move);
33
34 CPPUNIT_ASSERT(! record.findLoopInList(pathBefore));
35 CPPUNIT_ASSERT(! record.findLoopInList(pathAfter));
36 CPPUNIT_ASSERT(! move.findLoopInList(pathBefore));
37 // CPPUNIT_ASSERT(! move.findLoopInList(pathAfter)); // 手番エラー
38
39 record.setLoopDetection(pathAfter, 0);
40 // CPPUNIT_ASSERT(! record.findLoopInList(pathBefore));
41 CPPUNIT_ASSERT(record.findLoopInList(pathAfter));
42 CPPUNIT_ASSERT(move.findLoopInList(pathBefore));
43 // CPPUNIT_ASSERT(! move.findLoopInList(pathAfter));
44 }
45
46 extern bool isShortTest;
47 void checkHashRecordTest::testSize()
48 {
49 if (! isShortTest)
50 std::cerr << sizeof(CheckHashRecord) <<"\n";
51 CPPUNIT_ASSERT(sizeof(CheckHashRecord) <= 128u);
52 }
53
54 void checkHashRecordTest::testFindDagOrigin()
55 {
56 #if 0
57 // 2003-12-07 現在は使っていないがテストケースはとっておく
58 {
59 // 相手が 0 なら 0
60 CheckHashRecord record;
61 CPPUNIT_ASSERT_EQUAL((CheckHashRecord*)0, record.findDagOrigin(0,true));
62 }
63 {
64 // a
65 // / \ これは対策不要
66 // b c
67 // \ /
68 // d
69 CheckHashRecord a, b, c, d;
70 a.moves.push_back(CheckMove(Move::INVALID(), &b));
71 a.moves.push_back(CheckMove(Move::INVALID(), &c));
72 b.moves.push_back(CheckMove(Move::INVALID(), &d));
73 b.parent = &a;
74 c.moves.push_back(CheckMove(Move::INVALID(), &d));
75 c.parent = &a;
76 CPPUNIT_ASSERT_EQUAL((CheckHashRecord*)0, b.findDagOrigin(&c,true));
77 }
78 {
79 // a
80 // / \ 対策必要
81 // b c
82 // | |
83 // d e
84 // \ /
85 // f
86 CheckHashRecord a, b, c, d, e, f;
87 a.moves.push_back(CheckMove(Move::INVALID(), &b));
88 a.moves.push_back(CheckMove(Move::INVALID(), &c));
89 b.moves.push_back(CheckMove(Move::INVALID(), &d));
90 b.parent = &a;
91 c.moves.push_back(CheckMove(Move::INVALID(), &e));
92 c.parent = &a;
93 d.parent = &b;
94 e.parent = &c;
95 d.setProofDisproof(b.proofDisproof());
96 e.setProofDisproof(c.proofDisproof());
97 CPPUNIT_ASSERT_EQUAL(&a, d.findDagOrigin(&e,true));
98 CPPUNIT_ASSERT_EQUAL(&a, d.findDagOrigin(&e,false));
99 CPPUNIT_ASSERT_EQUAL((CheckHashRecord*)0, a.findDagOrigin(0,true));
100
101 b.setProofDisproof(PawnCheckmate);
102 CPPUNIT_ASSERT_EQUAL((CheckHashRecord*)0, d.findDagOrigin(&e,true));
103 CPPUNIT_ASSERT_EQUAL((CheckHashRecord*)0, d.findDagOrigin(&e,false));
104 }
105 #endif
106 }
107
108 /* ------------------------------------------------------------------------- */
109 // ;;; Local Variables:
110 // ;;; mode:c++
111 // ;;; c-basic-offset:2
112 // ;;; End: