C:\xampp\phpMyAdmin\vendor\bacon\bacon-qr-code\tests\BaconQrCode\Common\ReedSolomonCodecTest.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
 * BaconQrCode
 *
 * @link      http://github.com/Bacon/BaconQrCode For the canonical source repository
 * @copyright 2013 Ben 'DASPRiD' Scholzen
 * @license   http://opensource.org/licenses/BSD-2-Clause Simplified BSD License
 */

namespace BaconQrCode\Common;

use 
PHPUnit_Framework_TestCase as TestCase;
use 
SplFixedArray;

class 
ReedSolomonTest extends TestCase
{
    public static function 
tabProvider()
    {
        return array(
            array(
20x7,   111),
            array(
30xb,   112),
            array(
40x13,  114),
            array(
50x25,  116),
            array(
60x43,  118),
            array(
70x89,  1110),
            array(
80x11d1132),
        );
    }

    
/**
     * @dataProvider tabProvider
     * @param        integer $symbolSize
     * @param        integer $generatorPoly
     * @param        integer $firstRoot
     * @param        integer $primitive
     * @param        integer $numRoots
     * @return       void
     */
    
public function testCodec($symbolSize$generatorPoly$firstRoot$primitive$numRoots)
    {
        if (
defined('MT_RAND_PHP')) {
            
mt_srand(0xdeadbeefMT_RAND_PHP);
        } else {
            
mt_srand(0xdeadbeef);
        }

        
$blockSize = (<< $symbolSize) - 1;
        
$dataSize  $blockSize $numRoots;
        
$codec     = new ReedSolomonCodec($symbolSize$generatorPoly$firstRoot$primitive$numRoots0);

        for (
$errors 0$errors <= $numRoots 2$errors++) {
            
// Load block with random data and encode
            
$block SplFixedArray::fromArray(array_fill(0$blockSize0), false);

            for (
$i 0$i $dataSize$i++) {
                
$block[$i] = mt_rand(0$blockSize);
            }

            
// Make temporary copy
            
$tBlock         = clone $block;
            
$parity         SplFixedArray::fromArray(array_fill(0$numRoots0), false);
            
$errorLocations SplFixedArray::fromArray(array_fill(0$blockSize0), false);
            
$erasures       = array();

            
// Create parity
            
$codec->encode($block$parity);

            
// Copy parity into test blocks
            
for ($i 0$i $numRoots$i++) {
                
$block[$i $dataSize] = $parity[$i];
                
$tBlock[$i $dataSize] = $parity[$i];
            }

            
// Seed with errors
            
for ($i 0$i $errors$i++) {
                
$errorValue mt_rand(1$blockSize);

                do {
                    
$errorLocation mt_rand(0$blockSize);
                } while (
$errorLocations[$errorLocation] !== 0);

                
$errorLocations[$errorLocation] = 1;

                if (
mt_rand(01)) {
                    
$erasures[] = $errorLocation;
                }

                
$tBlock[$errorLocation] ^= $errorValue;
            }

            
$erasures SplFixedArray::fromArray($erasuresfalse);

            
// Decode the errored block
            
$foundErrors $codec->decode($tBlock$erasures);

            if (
$errors && $foundErrors === null) {
                
$this->assertEquals($block$tBlock'Decoder failed to correct errors');
            }

            
$this->assertEquals($errors$foundErrors'Found errors do not equal expected errors');

            for (
$i 0$i $foundErrors$i++) {
                if (
$errorLocations[$erasures[$i]] === 0) {
                    
$this->fail(sprintf('Decoder indicates error in location %d without error'$erasures[$i]));
                }
            }

            
$this->assertEquals($block$tBlock'Decoder did not correct errors');
        }
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586