Changeset View
Changeset View
Standalone View
Standalone View
autotests/solver_format.cpp
- This file was copied from golf.h.
| 1 | /* | 1 | /* | ||
|---|---|---|---|---|---|
| 2 | * Copyright (C) 2001-2009 Stephan Kulow <coolo@kde.org> | 2 | * Copyright (C) 1995 Paul Olav Tvete <paul@troll.no> | ||
| 3 | * Copyright (C) 2000-2009 Stephan Kulow <coolo@kde.org> | ||||
| 3 | * | 4 | * | ||
| 4 | * License of original code: | 5 | * License of original code: | ||
| 5 | * ------------------------------------------------------------------------- | 6 | * ------------------------------------------------------------------------- | ||
| 6 | * Permission to use, copy, modify, and distribute this software and its | 7 | * Permission to use, copy, modify, and distribute this software and its | ||
| 7 | * documentation for any purpose and without fee is hereby granted, | 8 | * documentation for any purpose and without fee is hereby granted, | ||
| 8 | * provided that the above copyright notice appear in all copies and that | 9 | * provided that the above copyright notice appear in all copies and that | ||
| 9 | * both that copyright notice and this permission notice appear in | 10 | * both that copyright notice and this permission notice appear in | ||
| 10 | * supporting documentation. | 11 | * supporting documentation. | ||
| Show All 16 Lines | |||||
| 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 29 | * GNU General Public License for more details. | 30 | * GNU General Public License for more details. | ||
| 30 | * | 31 | * | ||
| 31 | * You should have received a copy of the GNU General Public License | 32 | * You should have received a copy of the GNU General Public License | ||
| 32 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 33 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 33 | * ------------------------------------------------------------------------- | 34 | * ------------------------------------------------------------------------- | ||
| 34 | */ | 35 | */ | ||
| 35 | 36 | // Based on main.cpp | |||
| 36 | #ifndef GOLF_H | 37 | #include <QTest> | ||
| 37 | #define GOLF_H | | |||
| 38 | | ||||
| 39 | #include "dealer.h" | 38 | #include "dealer.h" | ||
| 39 | #include "dealerinfo.h" | ||||
| 40 | #include "golf.h" | ||||
| 41 | #include "../kpat_debug.h" | ||||
| 40 | 42 | | |||
| 41 | 43 | class TestSolverFormat: public QObject | |||
| 42 | class Golf : public DealerScene | | |||
| 43 | { | 44 | { | ||
| 44 | Q_OBJECT | 45 | Q_OBJECT | ||
| 46 | private slots: | ||||
| 47 | void solverFormat_deal1(); | ||||
| 48 | }; | ||||
| 45 | 49 | | |||
| 46 | public: | 50 | static DealerScene *getDealer( int wanted_game ) | ||
| 47 | explicit Golf( const DealerInfo * di ); | 51 | { | ||
| 48 | void initialize() Q_DECL_OVERRIDE; | 52 | fprintf(stderr, "diuuuuu=\n"); | ||
| 49 | #ifdef WITH_BH_SOLVER | 53 | foreach ( DealerInfo * di, DealerInfoList::self()->games() ) | ||
| 50 | QString solverFormat() const; | 54 | { | ||
| 51 | #endif | 55 | fprintf(stderr, "di=%p\n", di); | ||
| 52 | 56 | if ( di->providesId( wanted_game ) ) | |||
| 53 | protected: | 57 | { | ||
| 54 | void setGameState( const QString & state ) Q_DECL_OVERRIDE; | 58 | DealerScene * d = di->createGame(); | ||
| 55 | bool checkAdd(const PatPile * pile, const QList<KCard*> & oldCards, const QList<KCard*> & newCards) const Q_DECL_OVERRIDE; | 59 | Q_ASSERT( d ); | ||
| 56 | bool checkRemove(const PatPile * pile, const QList<KCard*> & cards) const Q_DECL_OVERRIDE; | 60 | d->setDeck( new KCardDeck( KCardTheme(), d ) ); | ||
| 57 | void restart( const QList<KCard*> & cards ) Q_DECL_OVERRIDE; | 61 | d->initialize(); | ||
| 58 | bool drop() Q_DECL_OVERRIDE; | | |||
| 59 | | ||||
| 60 | protected slots: | | |||
| 61 | bool newCards() Q_DECL_OVERRIDE; | | |||
| 62 | | ||||
| 63 | private: | | |||
| 64 | PatPile* talon; | | |||
| 65 | PatPile* stack[7]; | | |||
| 66 | PatPile* waste; | | |||
| 67 | 62 | | |||
| 68 | friend class GolfSolver; | 63 | if ( !d->solver() ) | ||
| 69 | }; | 64 | { | ||
| 65 | qCCritical(KPAT_LOG) << "There is no solver for" << di->nameForId( wanted_game );; | ||||
| 66 | return nullptr; | ||||
| 67 | } | ||||
| 68 | | ||||
| 69 | return d; | ||||
| 70 | } | ||||
| 71 | } | ||||
| 72 | return nullptr; | ||||
| 73 | } | ||||
| 74 | | ||||
| 75 | void TestSolverFormat::solverFormat_deal1() | ||||
| 76 | { | ||||
| 77 | DealerScene *f = getDealer( DealerInfo::GolfId ); | ||||
| 78 | assert(f); | ||||
| 79 | f->deck()->stopAnimations(); | ||||
| 80 | f->startNew( 1 ); | ||||
| 81 | QString have = static_cast<Golf *>(f)->solverFormat(); | ||||
| 82 | QString want( | ||||
| 83 | "Foundations: TH\n" | ||||
| 84 | "Talon: 8H 2C JH 7D 6D 8S 8D QS 6C 3D 8C TC 6S 9C 2H 6H\n" | ||||
| 85 | "JD 5H KH AS 4H\n" | ||||
| 86 | "2D KD 3H AH AC\n" | ||||
| 87 | "9H KC 2S 3C 4D\n" | ||||
| 88 | "JC 9S KS 4C 7S\n" | ||||
| 89 | "5D 5S 9D 5C 3S\n" | ||||
| 90 | "7H AD QD TS TD\n" | ||||
| 91 | "7C QC JS QH 4S\n" | ||||
| 92 | ); | ||||
| 93 | QCOMPARE(have, want); | ||||
| 94 | } | ||||
| 70 | 95 | | |||
| 71 | #endif | 96 | QTEST_MAIN(TestSolverFormat) | ||
| 97 | #include "solver_format.moc" | ||||