<commit_before><?php
/**
 * Hostingcheck (https://github.com/zero2one/hostingcheck)
 *
 * @link      https://github.com/zero2one/hostingcheck source repository.
 * @copyright Copyright (c) 2005-2014 Serial Graphics. (http://serial-graphics.be)
 * @license   http://opensource.org/licenses/GPL-2.0 GNU Public License
 */


/**
 * Tests for Hostingcheck_Value_Boolean
 *
 * @author <NAME> <<EMAIL>>
 */
class Hostingcheck_Value_Boolean_TestCase extends PHPUnit_Framework_TestCase
{
    /**
     * Test getValue method without value in the constructor.
     */
    public function testGetValueWithoutValueInConstructor()
    {
        $boolean = new Hostingcheck_Value_Boolean();
        $this->assertEquals(false, $boolean->getValue());
    }

    /**
     * Check getValue method.
     *
     * @param mixed $value
     *     The value to test.
     * @param bool $expected
     *     The expected boolean value.
     *
     * @dataProvider getValueProvider
     */
    public function testGetValue($value, $expected)
    {
        $boolean = new Hostingcheck_Value_Boolean($value);
        $this->assertEquals($expected, $boolean->getValue());
    }

    /**
     * Test exception when setting non supported format.
     *
     * @expectedException Exception
     */
    public function testFormatException()
    {
        $boolean = new Hostingcheck_Value_Boolean(false);
        $boolean->setFormat('fooBar');
    }

    /**
     * Test to string when no format is set.
     */
    public function testToStringWithoutFormatSet()
    {
        $boolean = new Hostingcheck_Value_Boolean(false);
        $this->assertEquals('false', (string) $boolean);

        $boolean = new Hostingcheck_Value_Boolean(true);
        $this->assertEquals('true', (string) $boolean);
    }

    /**
     * Check get string.
     *
     * @param mixed $value
     *     The value to test.
     * @param string $format
     *     The expected format.
     * @param string $expected
     *     The expected output value.
     *
     * @dataProvider getToStringProvider
     */
    public function testToString($value, $format, $expected)
    {
        $boolean = new Hostingcheck_Value_Boolean($value);
        $boolean->setFormat($format);
        $this->assertEquals($expected, (string) $boolean);
    }


    /**
     * dataProvider for testGetValue().
     *
     * @return array
     */
    public function getValueProvider()
    {
        return array(
            // NULL.
            array( null,  false),
            array('null', false),

            // True/False.
            array( false,  false),
            array('false', false),
            array( true,   true),
            array('true',  true),

            // Integer.
            array( 0,  false),
            array('0', false),
            array( 1,  true),
            array('1', true),

            // Float
            array( 0.0,  false),
            array('0.0', false),
            array( 0.1,  true),
            array('0.1', true),

            // On/Off.
            array( 'on', true),
            array('off', false),

            // Yes/No.
            array('yes', true),
            array( 'no', false),

            // Special.
            array( array(), false),
            array(array(1), true),
            array(new stdClass(), true),
        );
    }

    /**
     * dataProvider for testToString().
     *
     * @return array
     */
    public function getToStringProvider()
    {
        $boolean = Hostingcheck_Value_Boolean::BOOLEAN;
        $integer = Hostingcheck_Value_Boolean::INTEGER;
        $on_off  = Hostingcheck_Value_Boolean::ON_OFF;
        $yes_no  = Hostingcheck_Value_Boolean::YES_NO;

        return array(
            // Boolean.
            array(false, $boolean, 'false'),
            array(true,  $boolean, 'true'),

            // Integer.
            array(false, $integer, '0'),
            array(true,  $integer, '1'),

            // On/Off.
            array(false, $on_off, 'off'),
            array(true,  $on_off, 'on'),

            // Yes/No.
            array(false, $yes_no, 'no'),
            array(true,  $yes_no, 'yes'),<commit_msg>Added missing test for empty & non supported strings.<commit_after><?php
/**
 * Hostingcheck (https://github.com/zero2one/hostingcheck)
 *
 * @link      https://github.com/zero2one/hostingcheck source repository.
 * @copyright Copyright (c) 2005-2014 Serial Graphics. (http://serial-graphics.be)
 * @license   http://opensource.org/licenses/GPL-2.0 GNU Public License
 */


/**
 * Tests for Hostingcheck_Value_Boolean
 *
 * @author <NAME> <<EMAIL>>
 */
class Hostingcheck_Value_Boolean_TestCase extends PHPUnit_Framework_TestCase
{
    /**
     * Test getValue method without value in the constructor.
     */
    public function testGetValueWithoutValueInConstructor()
    {
        $boolean = new Hostingcheck_Value_Boolean();
        $this->assertEquals(false, $boolean->getValue());
    }

    /**
     * Check getValue method.
     *
     * @param mixed $value
     *     The value to test.
     * @param bool $expected
     *     The expected boolean value.
     *
     * @dataProvider getValueProvider
     */
    public function testGetValue($value, $expected)
    {
        $boolean = new Hostingcheck_Value_Boolean($value);
        $this->assertEquals($expected, $boolean->getValue());
    }

    /**
     * Test exception when setting non supported format.
     *
     * @expectedException Exception
     */
    public function testFormatException()
    {
        $boolean = new Hostingcheck_Value_Boolean(false);
        $boolean->setFormat('fooBar');
    }

    /**
     * Test to string when no format is set.
     */
    public function testToStringWithoutFormatSet()
    {
        $boolean = new Hostingcheck_Value_Boolean(false);
        $this->assertEquals('false', (string) $boolean);

        $boolean = new Hostingcheck_Value_Boolean(true);
        $this->assertEquals('true', (string) $boolean);
    }

    /**
     * Check get string.
     *
     * @param mixed $value
     *     The value to test.
     * @param string $format
     *     The expected format.
     * @param string $expected
     *     The expected output value.
     *
     * @dataProvider getToStringProvider
     */
    public function testToString($value, $format, $expected)
    {
        $boolean = new Hostingcheck_Value_Boolean($value);
        $boolean->setFormat($format);
        $this->assertEquals($expected, (string) $boolean);
    }


    /**
     * dataProvider for testGetValue().
     *
     * @return array
     */
    public function getValueProvider()
    {
        return array(
            // Empty
            array('', false),
            array(' ', false),

            // NULL.
            array( null,  false),
            array('null', false),

            // True/False.
            array( false,  false),
            array('false', false),
            array( true,   true),
            array('true',  true),

            // Integer.
            array( 0,  false),
            array('0', false),
            array( 1,  true),
            array('1', true),

            // Float
            array( 0.0,  false),
            array('0.0', false),
            array( 0.1,  true),
            array('0.1', true),

            // On/Off.
            array( 'on', true),
            array('off', false),

            // Yes/No.
            array('yes', true),
            array( 'no', false),

            // Special.
            array( array(), false),
            array(array(1), true),
            array(new stdClass(), true),

            // Non supported strings.
            array('whatever', true),
        );
    }

    /**
     * dataProvider for testToString().
     *
     * @return array
     */
    public function getToStringProvider()
    {
        $boolean = Hostingcheck_Value_Boolean::BOOLEAN;
        $integer = Hostingcheck_Value_Boolean::INTEGER;
        $on_off  = Hostingcheck_Value_Boolean::ON_OFF;
        $yes_no  = Hostingcheck_Value_Boolean::YES_NO;

        return array(
            // Boolean.
            array(false, $boolean, 'false'),
            array(true,  $boolean, 'true'),

            // Integer.
            array(false, $integer, '0'),
            array(true,  $integer, '1'),

            // On/Off.
            array(false, $on_off, 'off'),
            array(true,  $on_off, 'on'),

            // Yes/No.
            array(false, $yes_no, 'no'),
            array(true,  $yes_no, 'yes'),
{'fraction_non_alphanumeric': 0.1315200753561757, 'fraction_numerical': 0.006358177322500883, 'mean_word_length': 1.8238031914893618, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 4, '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': '5441567', 'n_tokens_mistral': 2416, 'n_tokens_neox': 2350, 'n_words': 546}