File indexing completed on 2024-05-26 04:28:01

0001 /*
0002  *  SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "KisPerStrokeRandomSourceTest.h"
0008 
0009 #include "brushengine/KisPerStrokeRandomSource.h"
0010 
0011 #include <simpletest.h>
0012 
0013 void KisPerStrokeRandomSourceTest::testIndependent()
0014 {
0015     bool sourcesDiffer = false;
0016 
0017     /**
0018      * Theoretically, the we can get two equal 1000-pcs sequences, but it is highly improbable
0019      */
0020     for (int i = 0; i < 1000; i++) {
0021         KisPerStrokeRandomSource s1;
0022         KisPerStrokeRandomSource s2;
0023 
0024         if (s1.generate("mykey", 0, 1000) != s2.generate("mykey", 0, 1000)) {
0025             sourcesDiffer = true;
0026             break;
0027         }
0028     }
0029 
0030     QVERIFY(sourcesDiffer);
0031 }
0032 
0033 void KisPerStrokeRandomSourceTest::testDependent()
0034 {
0035     bool allSame = true;
0036 
0037     for (int i = 0; i < 1000; i++) {
0038         KisPerStrokeRandomSource s1;
0039         KisPerStrokeRandomSource s2(s1);
0040 
0041         if (s1.generate("mykey", 0, 1000) != s2.generate("mykey", 0, 1000)) {
0042             allSame = false;
0043             break;
0044         }
0045     }
0046 
0047     QVERIFY(allSame);
0048 }
0049 
0050 void KisPerStrokeRandomSourceTest::testDifferentKeys()
0051 {
0052     bool sourcesDiffer = false;
0053 
0054     /**
0055      * Theoretically, the we can get two equal 1000-pcs sequences, but it is highly improbable
0056      */
0057     for (int i = 0; i < 1000; i++) {
0058         KisPerStrokeRandomSource s1;
0059         KisPerStrokeRandomSource s2(s1);
0060 
0061         if (s1.generate("mykey1", 0, 1000) != s2.generate("mykey2", 0, 1000)) {
0062             sourcesDiffer = true;
0063             break;
0064         }
0065     }
0066 
0067     QVERIFY(sourcesDiffer);
0068 }
0069 
0070 SIMPLE_TEST_MAIN(KisPerStrokeRandomSourceTest)