<commit_before><?php
namespace RandomLib;

class GeneratorStringTest extends \PHPUnit_Framework_TestCase {

    protected $generator = null;
    protected $mixer = null;
    protected $sources = array();

    public static function provideCharCombinations() {
        return array(
            array("CHAR_LOWER", implode("", range("a", "z"))),
            array("CHAR_UPPER", implode("", range("A", "Z"))),
            array("CHAR_DIGITS", implode("", range(0, 9))),
            array("CHAR_UPPER_HEX", "0123456789ABCDEF"),
            array("CHAR_LOWER_HEX", "0123456789abcdef"),
            array("CHAR_BASE64", "+/0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"),
            array("EASY_TO_READ", "3479ACEFHJKLMNPRTUVWXYabcdefghijkmnopqrstuvwxyz"),
            array("CHAR_BRACKETS", "()<>[]{}"),
            array("CHAR_SYMBOLS", " !\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"),
            array("CHAR_PUNCT", ",.:;"),
            array("CHAR_ALPHA", implode("", array_merge(range("A", "Z"), range("a", "z")))),
            array("CHAR_ALNUM", implode("", array_merge(range(0, 9), range("A", "Z"), range("a", "z")))),
            array("CHAR_ALPHA | PUNCT", ",.:;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", Generator::CHAR_ALPHA | Generator::CHAR_PUNCT),
            array("CHAR_LOWER | EASY_TO_READ", "abcdefghijkmnopqrstuvwxyz", Generator::CHAR_LOWER | Generator::EASY_TO_READ),
            array("CHAR_DIGITS | EASY_TO_READ", "3479", Generator::CHAR_DIGITS | Generator::EASY_TO_READ),
        );
    }

    public function setUp() {
        $source1 = $this->getMock('RandomLib\Source');
        $source1->expects($this->any())
            ->method('generate')
            ->will($this->returnCallback(function ($size) {
                $r = '';
                for ($i = 0; $i < $size; $i++) {
                    $r .= chr($i % 256);
                }
                return $r;
            }
        ));
        $source2 = $this->getMock('RandomLib\Source');
        $source2->expects($this->any())
            ->method('generate')
            ->will($this->returnCallback(function ($size) {
                $r = '';
                for ($i = 0; $i < $size; $i++) {
                    $r .= chr(0);
                }
                return $r;
            }
        ));

        $this->mixer = $this->getMock('RandomLib\Mixer');
        $this->mixer->expects($this->any())
            ->method('mix')
            ->will($this->returnCallback(function(array $sources) {
                if (empty($sources)) return '';
                $start = array_pop($sources);
                return array_reduce(
                    $sources,
                    function($el1, $el2) {
                        return $el1 ^ $el2;
                    },
                    $start
                );
            }));

        $this->sources = array($source1, $source2);
        $this->generator = new Generator($this->sources, $this->mixer);
    }

    /**
     * @dataProvider provideCharCombinations
     */
    public function testScheme($schemeName, $expected, $scheme = 0) {
        // test for overspecification by doubling the expected amount
        if (!$scheme) {
            $scheme = constant("RandomLib\Generator::$schemeName");
        }
        $chars = $this->generator->generateString(strlen($expected) * 2, $scheme);
        if ($hexOut) {
            $chars = bin2hex($chars);
            $expected = bin2hex($expected);
        }
        $this->assertEquals($expected . $expected, $chars, sprintf("Testing Generator::%s failed", $schemeName));
    }

    public function testHigh() {
        $expected = implode("", array_map("chr", range(128, 255)));
        $expected .= $expected;
        
        $actual = bin2hex($this->generator->generateString(strlen($expected), Generator::CHAR_HIGH));
        $expected = bin2hex($expected);
    
        $this->assertEquals($expected, $actual);
    }    

}<commit_msg>Fix stupid missing variable error. Doh<commit_after><?php
namespace RandomLib;

class GeneratorStringTest extends \PHPUnit_Framework_TestCase {

    protected $generator = null;
    protected $mixer = null;
    protected $sources = array();

    public static function provideCharCombinations() {
        return array(
            array("CHAR_LOWER", implode("", range("a", "z"))),
            array("CHAR_UPPER", implode("", range("A", "Z"))),
            array("CHAR_DIGITS", implode("", range(0, 9))),
            array("CHAR_UPPER_HEX", "0123456789ABCDEF"),
            array("CHAR_LOWER_HEX", "0123456789abcdef"),
            array("CHAR_BASE64", "+/0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"),
            array("EASY_TO_READ", "3479ACEFHJKLMNPRTUVWXYabcdefghijkmnopqrstuvwxyz"),
            array("CHAR_BRACKETS", "()<>[]{}"),
            array("CHAR_SYMBOLS", " !\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"),
            array("CHAR_PUNCT", ",.:;"),
            array("CHAR_ALPHA", implode("", array_merge(range("A", "Z"), range("a", "z")))),
            array("CHAR_ALNUM", implode("", array_merge(range(0, 9), range("A", "Z"), range("a", "z")))),
            array("CHAR_ALPHA | PUNCT", ",.:;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", Generator::CHAR_ALPHA | Generator::CHAR_PUNCT),
            array("CHAR_LOWER | EASY_TO_READ", "abcdefghijkmnopqrstuvwxyz", Generator::CHAR_LOWER | Generator::EASY_TO_READ),
            array("CHAR_DIGITS | EASY_TO_READ", "3479", Generator::CHAR_DIGITS | Generator::EASY_TO_READ),
        );
    }

    public function setUp() {
        $source1 = $this->getMock('RandomLib\Source');
        $source1->expects($this->any())
            ->method('generate')
            ->will($this->returnCallback(function ($size) {
                $r = '';
                for ($i = 0; $i < $size; $i++) {
                    $r .= chr($i % 256);
                }
                return $r;
            }
        ));
        $source2 = $this->getMock('RandomLib\Source');
        $source2->expects($this->any())
            ->method('generate')
            ->will($this->returnCallback(function ($size) {
                $r = '';
                for ($i = 0; $i < $size; $i++) {
                    $r .= chr(0);
                }
                return $r;
            }
        ));

        $this->mixer = $this->getMock('RandomLib\Mixer');
        $this->mixer->expects($this->any())
            ->method('mix')
            ->will($this->returnCallback(function(array $sources) {
                if (empty($sources)) return '';
                $start = array_pop($sources);
                return array_reduce(
                    $sources,
                    function($el1, $el2) {
                        return $el1 ^ $el2;
                    },
                    $start
                );
            }));

        $this->sources = array($source1, $source2);
        $this->generator = new Generator($this->sources, $this->mixer);
    }

    /**
     * @dataProvider provideCharCombinations
     */
    public function testScheme($schemeName, $expected, $scheme = 0) {
        // test for overspecification by doubling the expected amount
        if (!$scheme) {
            $scheme = constant("RandomLib\Generator::$schemeName");
        }
        $chars = $this->generator->generateString(strlen($expected) * 2, $scheme);
        $this->assertEquals($expected . $expected, $chars, sprintf("Testing Generator::%s failed", $schemeName));
    }

    public function testHigh() {
        $expected = implode("", array_map("chr", range(128, 255)));
        $expected .= $expected;
        
        $actual = bin2hex($this->generator->generateString(strlen($expected), Generator::CHAR_HIGH));
        $expected = bin2hex($expected);
    
        $this->assertEquals($expected, $actual);
    }    

}
{'fraction_non_alphanumeric': 0.17259923175416134, 'fraction_numerical': 0.01818181818181818, 'mean_word_length': 2.161068393363011, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6976670', 'n_tokens_mistral': 2507, 'n_tokens_neox': 2347, 'n_words': 385}