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 (0 !== $errorLocations[$errorLocation]); $errorLocations[$errorLocation] = 1; if (mt_rand(0, 1)) { $erasures[] = $errorLocation; } $tBlock[$errorLocation] ^= $errorValue; } $erasures = SplFixedArray::fromArray($erasures, false); // Decode the errored block $foundErrors = $codec->decode($tBlock, $erasures); if ($errors > 0 && null === $foundErrors) { $this->assertSame($block, $tBlock, 'Decoder failed to correct errors'); } $this->assertSame($errors, $foundErrors, 'Found errors do not equal expected errors'); for ($i = 0; $i < $foundErrors; ++$i) { if (0 === $errorLocations[$erasures[$i]]) { $this->fail(sprintf('Decoder indicates error in location %d without error', $erasures[$i])); } } $this->assertEquals($block, $tBlock, 'Decoder did not correct errors'); } } }