| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | #include <QtTest/QtTest> |
| 29 | #include <QtTest/qtestcase.h> |
| 30 | #include <QtTest/QSignalSpy> |
| 31 | #include <QtCore/QBuffer> |
| 32 | #include <QtCore/QByteArray> |
| 33 | #include <QtCore/QDebug> |
| 34 | |
| 35 | #include "private/qdefaultmaskgenerator_p.h" |
| 36 | |
| 37 | QT_USE_NAMESPACE |
| 38 | |
| 39 | class tst_QDefaultMaskGenerator : public QObject |
| 40 | { |
| 41 | Q_OBJECT |
| 42 | |
| 43 | public: |
| 44 | tst_QDefaultMaskGenerator(); |
| 45 | |
| 46 | private Q_SLOTS: |
| 47 | void initTestCase(); |
| 48 | void cleanupTestCase(); |
| 49 | void init(); |
| 50 | void cleanup(); |
| 51 | |
| 52 | void tst_randomnessWithoutSeed(); |
| 53 | void tst_randomnessWithSeed(); |
| 54 | |
| 55 | private: |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | |
| 60 | tst_QDefaultMaskGenerator::tst_QDefaultMaskGenerator() |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | void tst_QDefaultMaskGenerator::initTestCase() |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | void tst_QDefaultMaskGenerator::cleanupTestCase() |
| 69 | { |
| 70 | } |
| 71 | |
| 72 | void tst_QDefaultMaskGenerator::init() |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | void tst_QDefaultMaskGenerator::cleanup() |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | void tst_QDefaultMaskGenerator::tst_randomnessWithoutSeed() |
| 81 | { |
| 82 | //generate two series of data, and see if they differ |
| 83 | { |
| 84 | QDefaultMaskGenerator generator; |
| 85 | |
| 86 | QVector<quint32> series1, series2; |
| 87 | for (int i = 0; i < 1000; ++i) |
| 88 | series1 << generator.nextMask(); |
| 89 | for (int i = 0; i < 1000; ++i) |
| 90 | series2 << generator.nextMask(); |
| 91 | |
| 92 | QVERIFY(series1 != series2); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | void tst_QDefaultMaskGenerator::tst_randomnessWithSeed() |
| 97 | { |
| 98 | //generate two series of data, and see if they differ |
| 99 | //the generator is seeded |
| 100 | { |
| 101 | QDefaultMaskGenerator generator; |
| 102 | generator.seed(); |
| 103 | |
| 104 | QVector<quint32> series1, series2; |
| 105 | for (int i = 0; i < 1000; ++i) |
| 106 | series1 << generator.nextMask(); |
| 107 | for (int i = 0; i < 1000; ++i) |
| 108 | series2 << generator.nextMask(); |
| 109 | |
| 110 | QVERIFY(series1 != series2); |
| 111 | } |
| 112 | //generates two series of data with 2 distinct generators |
| 113 | //both generators are seeded |
| 114 | { |
| 115 | QDefaultMaskGenerator generator1, generator2; |
| 116 | generator1.seed(); |
| 117 | generator2.seed(); |
| 118 | |
| 119 | QVector<quint32> series1, series2; |
| 120 | for (int i = 0; i < 1000; ++i) { |
| 121 | series1 << generator1.nextMask(); |
| 122 | series2 << generator2.nextMask(); |
| 123 | } |
| 124 | |
| 125 | QVERIFY(series1 != series2); |
| 126 | } |
| 127 | //generates two series of data with 2 distinct generators |
| 128 | //only one of the two is seeded |
| 129 | { |
| 130 | QDefaultMaskGenerator generator1, generator2; |
| 131 | generator1.seed(); |
| 132 | |
| 133 | QVector<quint32> series1, series2; |
| 134 | for (int i = 0; i < 1000; ++i) { |
| 135 | series1 << generator1.nextMask(); |
| 136 | series2 << generator2.nextMask(); |
| 137 | } |
| 138 | |
| 139 | QVERIFY(series1 != series2); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | QTEST_MAIN(tst_QDefaultMaskGenerator) |
| 144 | |
| 145 | #include "tst_defaultmaskgenerator.moc" |
| 146 | |