File indexing completed on 2024-05-19 07:53:18

0001 /*
0002  * Copyright (C) 1995 Paul Olav Tvete <paul@troll.no>
0003  * Copyright (C) 2000-2009 Stephan Kulow <coolo@kde.org>
0004  *
0005  * License of original code:
0006  * -------------------------------------------------------------------------
0007  *   Permission to use, copy, modify, and distribute this software and its
0008  *   documentation for any purpose and without fee is hereby granted,
0009  *   provided that the above copyright notice appear in all copies and that
0010  *   both that copyright notice and this permission notice appear in
0011  *   supporting documentation.
0012  *
0013  *   This file is provided AS IS with no warranties of any kind.  The author
0014  *   shall have no liability with respect to the infringement of copyrights,
0015  *   trade secrets or any patents by this file or any part thereof.  In no
0016  *   event will the author be liable for any lost revenue or profits or
0017  *   other special, indirect and consequential damages.
0018  * -------------------------------------------------------------------------
0019  *
0020  * License of modifications/additions made after 2009-01-01:
0021  * -------------------------------------------------------------------------
0022  *   This program is free software; you can redistribute it and/or
0023  *   modify it under the terms of the GNU General Public License as
0024  *   published by the Free Software Foundation; either version 2 of
0025  *   the License, or (at your option) any later version.
0026  *
0027  *   This program is distributed in the hope that it will be useful,
0028  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0029  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0030  *   GNU General Public License for more details.
0031  *
0032  *   You should have received a copy of the GNU General Public License
0033  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
0034  * -------------------------------------------------------------------------
0035  */
0036 // Based on main.cpp
0037 #include <QTest>
0038 #include "dealer.h"
0039 #include "dealerinfo.h"
0040 #include "golf.h"
0041 #include "../kpat_debug.h"
0042 
0043 #include <cassert>
0044 
0045 class TestSolverFormat: public QObject
0046 {
0047     Q_OBJECT
0048 private Q_SLOTS:
0049     void solverFormat_deal1();
0050 };
0051 
0052 static DealerScene *getDealer( int wanted_game )
0053 {
0054     fprintf(stderr, "diuuuuu=%d\n", wanted_game);
0055     const auto games = DealerInfoList::self()->games();
0056     for (DealerInfo * di : games) {
0057         fprintf(stderr, "di=%p\n", (void *)di);
0058         if ( di->providesId( wanted_game ) )
0059         {
0060             DealerScene * d = di->createGame();
0061             Q_ASSERT( d );
0062             d->setDeck( new KCardDeck( KCardTheme(), d ) );
0063             d->initialize();
0064 
0065             if ( !d->solver() )
0066             {
0067                 qCCritical(KPAT_LOG) << "There is no solver for" << di->nameForId( wanted_game );;
0068                 return nullptr;
0069             }
0070 
0071             return d;
0072         }
0073     }
0074     return nullptr;
0075 }
0076 
0077 void TestSolverFormat::solverFormat_deal1()
0078 {
0079     DealerScene *dealer = getDealer(DealerInfo::GolfId);
0080     assert(dealer);
0081     dealer->deck()->stopAnimations();
0082     dealer->startNew(1);
0083     QString have = static_cast<Golf *>(dealer)->solverFormat();
0084     QString want(
0085         "Foundations: TH\n"
0086         "Talon: 8H 2C JH 7D 6D 8S 8D QS 6C 3D 8C TC 6S 9C 2H 6H\n"
0087         "JD 5H KH AS 4H\n"
0088         "2D KD 3H AH AC\n"
0089         "9H KC 2S 3C 4D\n"
0090         "JC 9S KS 4C 7S\n"
0091         "5D 5S 9D 5C 3S\n"
0092         "7H AD QD TS TD\n"
0093         "7C QC JS QH 4S\n"
0094     );
0095     QCOMPARE(have, want);
0096     delete dealer;
0097 }
0098 
0099 QTEST_MAIN(TestSolverFormat)
0100 #include "solver_format.moc"