File indexing completed on 2024-05-19 07:53:18
0001 /* 0002 * Copyright (C) 2018 Shlomi Fish <shlomif@cpan.org> 0003 * 0004 * Permission is hereby granted, free of charge, to any person obtaining 0005 * a copy of this software and associated documentation files (the 0006 * "Software"), to deal in the Software without restriction, including 0007 * without limitation the rights to use, copy, modify, merge, publish, 0008 * distribute, sublicense, and/or sell copies of the Software, and to 0009 * permit persons to whom the Software is furnished to do so, subject to 0010 * the following conditions: 0011 * 0012 * The above copyright notice and this permission notice shall be included 0013 * in all copies or substantial portions of the Software. 0014 * 0015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 0016 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 0017 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 0018 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 0019 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 0020 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 0021 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 0022 */ 0023 0024 #include <QTest> 0025 #include "shuffle.h" 0026 0027 class TestCardsShuffle: public QObject 0028 { 0029 Q_OBJECT 0030 private Q_SLOTS: 0031 void shuffle_seed1(); 0032 void shuffle_seed24(); 0033 }; 0034 0035 typedef const char * Card; 0036 typedef QList<Card> CardList; 0037 0038 0039 const CardList input({"AC", "AD", "AH", "AS", "2C", "2D", "2H", "2S", "3C", "3D", "3H", "3S", "4C", "4D", "4H", "4S", "5C", "5D", "5H", "5S", "6C", "6D", "6H", "6S", "7C", "7D", "7H", "7S", "8C", "8D", "8H", "8S", "9C", "9D", "9H", "9S", "TC", "TD", "TH", "TS", "JC", "JD", "JH", "JS", "QC", "QD", "QH", "QS", "KC", "KD", "KH", "KS"} 0040 ); 0041 0042 void TestCardsShuffle::shuffle_seed1() 0043 { 0044 CardList have = KpatShuffle::shuffled<Card>(input, 1); 0045 CardList want( 0046 {"6H", "2H", "9C", "6S", "TC", "8C", "3D", "6C", "QS", "8D", "8S", "6D", "7D", "JH", "2C", "8H", "TH", "4S", "TD", "3S", "7S", "4D", "AC", "4H", "QH", "TS", "5C", "4C", "3C", "AH", "AS", "JS", "QD", "9D", "KS", "2S", "3H", "KH", "QC", "AD", "5S", "9S", "KC", "KD", "5H", "7C", "7H", "5D", "JC", "9H", "2D", "JD"} 0047 ); 0048 QCOMPARE(have, want); 0049 } 0050 0051 void TestCardsShuffle::shuffle_seed24() 0052 { 0053 CardList have = KpatShuffle::shuffled<Card>(input, 24); 0054 CardList want( 0055 {"AS", "3D", "QD", "2H", "9D", "JD", "7C", "8D", "6D", "KS", "4H", "4S", "8S", "8H", "KC", "TD", "JH", "3S", "3H", "QS", "4D", "AD", "TS", "TC", "5C", "9H", "AC", "8C", "7D", "6S", "KH", "TH", "JC", "6H", "3C", "9C", "6C", "5S", "JS", "KD", "2S", "9S", "QH", "2C", "7S", "AH", "7H", "2D", "5D", "QC", "5H", "4C"} 0056 ); 0057 QCOMPARE(have, want); 0058 } 0059 0060 QTEST_MAIN(TestCardsShuffle) 0061 #include "shuffle_test.moc"